Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readMacroParams to prevent errors #178

Open
YakovL opened this issue Jun 10, 2015 · 0 comments
Open

Improve readMacroParams to prevent errors #178

YakovL opened this issue Jun 10, 2015 · 0 comments
Labels

Comments

@YakovL
Copy link
Contributor

YakovL commented Jun 10, 2015

The problem

Currently String.prototype.readMacroParams helper [1] calls .parseParams method with noNames == true. It was probably coded this way as the calculated [2] params argument passed to a macro handler is meant to contain no param names. However, this approach causes errors. Here's a number of tests that you can copy to a TW and see the results:

|<<tiddler [[a {{DDn{b}}} c]]>>|{{{<<tiddler }}}<html><code>[[a {{DDn{b}}} c</code></html>{{{]]>>}}}|
|<<tiddler name:[[a {{DDn{b}}} c]]>>|{{{<<tiddler na}}}<html><code>me:[[a {{DDn{b}}} c</code></html>{{{]]>>}}}|
|<<tiddler name:[[{{DDn{b}}} c]]>>|{{{<<tiddler na}}}<html><code>me:[[{{DDn{b}}} c</code></html>{{{]]>>}}}|
|<<tiddler name:[[a {{DDn{b}}}]]>>|{{{<<tiddler na}}}<html><code>me:[[a {{DDn{b}}}</code></html>{{{]]>>}}}|
|<<tiddler name:"a {{DDn{b}}}">>|{{{<<tiddler na}}}<html><code>me:"a {{DDn{b}}}</code></html>{{{">>}}}|

In short, the 1st and the 3d lines don't cause any error while the other three cause the

Unable to evaluate {{DDn{b}}: SyntaxError: missing ; before statement

error. What's the reason?

The thing is, when .parseParams is called with noNames == true, it "thinks" that in

name:[[a {{DDn{b}}}]]

the first argument matches unQuoted [3] name:[[a and then the next match starts from {{ resulting in dblBrace matching {{DDn{b}}.

The solution

Now, after some analysis I've come to a simple solution: as this separation was not intended, we can simply call

var p = this.parseParams("_default",null,!notAllowEval);

in String.prototype.readMacroParams (instead of doing it like in the line 172) and then, because only p[t].value is pushed to results (name is omitted), the function works nicely (as expected, backward compatible) with "correctly used" macro params, but also doesn't cause any of the mentioned errors.

I've made a plugin that overwrites String.prototype.readMacroParams with the one containing the mentioned change, and it works nicely for me. But this looks like a core problem, so my proposal is to embed this into the core.

Best regards,
Yakov.

[1] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Strings.js#L170
[2] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Macros.js#L20
[3] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Strings.js#L128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants