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

noEscape cause additions of integer values #1838

Open
christophermhawaudio opened this issue Mar 19, 2022 · 5 comments
Open

noEscape cause additions of integer values #1838

christophermhawaudio opened this issue Mar 19, 2022 · 5 comments
Assignees
Labels

Comments

@christophermhawaudio
Copy link

Hello,

When I set the parameter "noEscape" to true, it seems that tokens are added instead of concatenated. So if I reference integers inside tokens, an addition will be realised if no separation character is present between tokens.

According to the documentation, "noEscape" is just a way to disable HTML characters escaping, and I think that a solution would be to use a string version of the variables referenced by the tokens instead of the variables values directly.

Here is an example of the bug with multiple cases: https://jsfiddle.net/mhd0k4ne/70/

Thanks.

@jaylinski jaylinski self-assigned this Mar 19, 2022
@jaylinski jaylinski removed their assignment Mar 19, 2022
@christophermhawaudio
Copy link
Author

Any news about this bug?

@rickyes
Copy link

rickyes commented Jun 21, 2022

@jaylinski Excuse me, is there any progress on this?

@jaylinski
Copy link
Member

I opened a fix PR: #1977

@nknapp
Copy link
Collaborator

nknapp commented Aug 6, 2023

Follownig up the discussion at #1977:

{{{a}}}{{{b}}}{{{c}}}

compiles to

{"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
    var stack1, helper, alias1=container.propertyIsEnumerable, alias2=depth0 != null ? depth0 : (container.nullContext || {}), alias3=container.hooks.helperMissing, alias4="function";

  return ((stack1 = ((helper = (helper = helpers.a || (depth0 != null ? depth0.a : depth0)) != null ? helper : alias3),(typeof helper === alias4 ? helper.call(alias2,{"name":"a","hash":{},"data":data}) : helper))) != null ? stack1 : "")
    + ((stack1 = ((helper = (helper = helpers.b || (depth0 != null ? depth0.b : depth0)) != null ? helper : alias3),(typeof helper === alias4 ? helper.call(alias2,{"name":"b","hash":{},"data":data}) : helper))) != null ? stack1 : "")
    + ((stack1 = ((helper = (helper = helpers.c || (depth0 != null ? depth0.c : depth0)) != null ? helper : alias3),(typeof helper === alias4 ? helper.call(alias2,{"name":"c","hash":{},"data":data}) : helper))) != null ? stack1 : "");
},"useData":true}

which boils down to

input.a + input.b + input.c

which adds integer values, giving the wrong output.

But the template

a{{{a}}}{{{b}}}{{{c}}}

becomes something like

"a" + input.a + input.b + input.c

which will always be a string and concatenate numbers.

I think in order to achieve this always, we just need to make sure that

{{{a}}}{{{b}}}{{{c}}}

becomes

"" + input.a + input.b + input.c

In those cases where the buffer added to (buffer += ...), we don't need it, because the buffer should already be a string.
I have to see wether I find the places to change this.

nknapp added a commit that referenced this issue Aug 6, 2023
@nknapp
Copy link
Collaborator

nknapp commented Aug 6, 2023

The place to change this would be line 311.

Changing this to

bufferStart.prepend('return "" + ');

should also make sure that everything is handled like a string.

  • The downside is three more bytes for the template and each block and partial statement, even if not needed.
  • The downside of your change is three bytes per non-escaped mustache-expression.

Difficult to say which one will produce more bytes in average.

jaylinski added a commit that referenced this issue Aug 29, 2023
Also removed `chai-diff`-dependency, since
it is unmaintained and not that useful.

Fixes #1838
jaylinski added a commit that referenced this issue Aug 29, 2023
Also removed `chai-diff`-dependency, since
it is unmaintained and not that useful.

Fixes #1838
@jaylinski jaylinski self-assigned this Aug 29, 2023
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

4 participants