-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Custom delimiters on Mustache.parse() not working since 2.3.1 #669
Comments
Thanks a lot for the report @mbrodala, those codepens are much appreciated! |
@mbrodala Thanks for the codepens. #643 and #664 fix a bug which I reported in #617 , which is illustrated by this test, which accompanies #643 : describe('when parsing a template with tags specified followed by the same template with different tags specified', function() {
it('returns different tokens for the latter parse', function() {
var template = "(foo)[bar]";
var parsedWithParens = Mustache.parse(template, ['(', ')']);
var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
assert.notDeepEqual(parsedWithBrackets, parsedWithParens);
});
}); The
I think I know what's going on with regard to the bug fix and expectations, and I'll try to walk through it, and I'll use the codepen as the example. v2.3.0Mustache.parse(template, ['[[', ']]']); In 2.3.0, this instructs Mustache to parse if (tokens == null)
tokens = cache[template] = parseTemplate(template, tags); The next call in the codepen is: var output = Mustache.render(
template,
...
v2.3.1Mustache.parse(template, ['[[', ']]']); The parse result is cached using both The next call: var output = Mustache.render(
template,
...
I believe v2.3.1 exhibits the correct behavior. If we were to change the codepen in https://codepen.io/mbrodala/pen/QBJoOx slightly and run it against v2.3.0: var template = "[[item.title]] [[item.value]]";
Mustache.parse(template, ['[[', ']]']);
var output = Mustache.render(
template,
{
item: {
title: "TEST",
value: 1
}
}
);
alert(output); The output is I can see how the behavior in https://codepen.io/mbrodala/pen/NBEJjX might be surprising, since the If the change in behavior really does defy the expectations of a bugfix release, then I'm not exactly sure what to do. One possibility is to release another bugfix version with #664 reverted, which in effect removes all caching behavior (given that in #643, all cache lookups will be misses). We could then put #664 back into the next major revision. Another possibility is to remove all caching in a bugfix release (as opposed to releasing a |
Thanks a lot for the detailed research which fully makes sense from my POV. I wouldn't mind about the change at all but given that it is impossible to pass If we assume that one calls |
@mbrodala Yes that makes sense, though Here is a straw-man solution/compromise ("straw-man" because I don't like it but it's worth brainstorming). We could have |
Sounds off and basically is but will fix this issue while keeping the fix intact. OK from my POV. |
@mbrodala is the core issue that you can't pass |
@petrkoutnysw Is this roughly the issue that you have been experiencing as well? |
It's at least an inconsistency between |
+1 for adding a tags parameter to render() to eliminate a lot of confusion -- we got bit by this change as well and the link b/w parse and render always seemed like a bit more magic than necessary.
|
Okay, so how about we disable caching in a bug fix release, to fix the immediate issue and comply with semantic versioning, and reintroduce it and |
Thanks a lot for that thorough walkthrough @raymond-lam! I'm leaning towards the suggested bug fix release, mainly because of semver concerns and projects where this change of behaviour is unexpected and can therefore cause havoc in projects out in the wild. Re-introducing the caching behaviour again in the planned next major release, we can include migration instructions in the release notes. |
@phillipj I've issued pull request #670 which rolls back #643 and #664. Rather than disabling caching all together, for the sake of risk mitigation, simply going back to v2.3.0 behavior (in a bugfix release) seems safest for dependents on Mustache v2.x.x. I will issue another pull request to reintroduce in a major release. |
Created issue #672 to address adding |
Thanks a lot for looking into and fixing this, you guys rock. 👍 |
Hats off to @raymond-lam for this one! Thanks to you as well, crucial for us to know when unexpected changes happens out in the wild. v2.3.2 has been published 🚀 |
Since version 2.3.1 custom delimiters apparently don't work anymore for
Mustache.parse()
. See the following examples:This is most likely related to #663 and its fix. Notice that I can restore this by using the newer
Mustache.tags = [...]
instead: https://codepen.io/mbrodala/pen/QBJoOxCan you please have a look at this?
The text was updated successfully, but these errors were encountered: