Skip to content
New issue

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

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

Already on GitHub? # to your account

Avoid the use of length attribute in custom helpers #1194

Closed
ManasJayanth opened this issue Mar 5, 2016 · 6 comments
Closed

Avoid the use of length attribute in custom helpers #1194

ManasJayanth opened this issue Mar 5, 2016 · 6 comments

Comments

@ManasJayanth
Copy link

When I compiled the following code


Usage:

{{#condense}}
{{#each usage}}
    {{#cyan}}bower{{/cyan}} {{.}}
{{/each}}
{{/condense}}


Options:

{{#condense}}
{{#each options}}
    {{#yellow}}{{#rpad length="23"}}{{#if shorthand}}{{shorthand}}, {{/if}}{{flag}}{{/rpad}}{{/yellow}} {{description}}
{{/each}}
{{/condense}}

    Additionally all global options listed in 'bower help' are available

Description:

    {{#indent level="4"}}{{description}}{{/indent}}

the following exception was observed.


/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:759
    hash.values[key] = value;
                     ^

RangeError: Invalid array length
    at Object.assignToHash (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:759:22)
    at Object.compile (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:113:27)
    at Object.compileChildren (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:794:49)
    at Object.compile (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:97:10)
    at Object.compileChildren (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:794:49)
    at Object.compile (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:97:10)
    at Object.compileChildren (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:794:49)
    at Object.compile (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:97:10)
    at compileInput (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:516:53)
    at ret (/Users/prometheansacrifice/development/js/handlebars-ex/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:523:18)

which can be traced to the following line

hash.values[key] = value;

On logging, I realised 'lengthis being set onhash.valueswith the value"23"`, which threw the RangeError.

Handlebars could prevent the use of reserved keywords in attributes for custom helpers

Handlebars version: 4.0.5

@kpdecker
Copy link
Collaborator

kpdecker commented Mar 7, 2016

Is this available on a public repository somewhere that we can run it locally?

@ManasJayanth
Copy link
Author

Try this repo

@kpdecker
Copy link
Collaborator

Thanks for the report. I've fixed this in master and added a test for it.

@ManasJayanth
Copy link
Author

Appreciate it. Thank you too.

nknapp pushed a commit that referenced this issue Mar 9, 2017
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors.

Fixes #1194
@philippe-granet
Copy link

@kpdecker @nknapp This fix is not reported in branch 3.x or 4.x ?

@nknapp
Copy link
Collaborator

nknapp commented Jan 18, 2019 via email

philippe-granet pushed a commit to philippe-granet/handlebars.js that referenced this issue Jan 18, 2019
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors.

Fixes handlebars-lang#1194
nknapp pushed a commit that referenced this issue Oct 27, 2019
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors.

Fixes #1194

(cherry picked from commit 768ddbd)
nknapp pushed a commit that referenced this issue Oct 27, 2019
The use of arrays was incorrect for the data type and causing problems when hash keys conflicted with array behaviors.

Fixes #1194

(cherry picked from commit 768ddbd)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants