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

Error when using ~ within {{{...}}} #2039

Open
danny0838 opened this issue Aug 21, 2024 · 6 comments
Open

Error when using ~ within {{{...}}} #2039

danny0838 opened this issue Aug 21, 2024 · 6 comments

Comments

@danny0838
Copy link

danny0838 commented Aug 21, 2024

Example 1:

Code:

const Handlebars = require('handlebars');
var tpl = Handlebars.compile("123\n{{{~myvar}}}\n123");
tpl({myvar: '<myvar>'});

Result:

Uncaught Error: Parse error on line 2:
123{{{~myvar}}}123
------^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'

Example 2:

Code:

const Handlebars = require('handlebars');
var tpl = Handlebars.compile("123\n{{{myvar~}}}\n123");
tpl({myvar: '<myvar>'});

Result:

Uncaught Error: Parse error on line 2:
123{{{myvar~}}}123
-----------^
Expecting 'CLOSE_UNESCAPED', 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'CLOSE'

Node.js: v21.6.2
handlebars: v4.7.8

@jaylinski
Copy link
Member

The following works:

const Handlebars = require('handlebars');
var tpl = Handlebars.compile("123\n{{~{myvar}}}\n123");
tpl({myvar: '<myvar>'});

I guess we should document this. I'm also not sure if this is in a specification.

@danny0838
Copy link
Author

Similar issue:

<script type="text/handlebars">
{{{{raw}}}}
{{something}}
{{{{/raw~}}}}
</script>

This causes an error, and {{{{/raw}}~}} doesn't work either.

@jaylinski
Copy link
Member

Similar issue:

<script type="text/handlebars">
{{{{raw}}}}
{{something}}
{{{{/raw~}}}}
</script>

This causes an error, and {{{{/raw}}~}} doesn't work either.

@danny0838 What is your expected output here?

@danny0838
Copy link
Author

Shouldn't it work normally to trim white spaces at the side? Or is there an alternative way to do this?

@jaylinski
Copy link
Member

jaylinski commented Sep 16, 2024

@danny0838
Copy link
Author

danny0838 commented Sep 17, 2024

trim doesn't work for such case as it removes white spaces between {{something}} and {{{{/raw~}}}}, while the intension of {{{{/raw~}}}} is to temove spaces between {{{{/raw~}}}} and </script>.

This issue is raised as such behavior seems like a bug (or at least inconsistent and counterintuitive). Is there any rationale to not implement {{{~...~}}} and {{{{~...~}}}} just like {{~...~}}? I think this is the most intuitive and what most users/developers would expect.

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

No branches or pull requests

2 participants