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

"each" helper throws "TypeError: ret.join is not a function" when the context is an empty list #9

Open
toverux opened this issue Oct 19, 2022 · 1 comment

Comments

@toverux
Copy link

toverux commented Oct 19, 2022

This error appears to happen when empty sources are passed to the each helper that is overriden by this library.

It's this line that crashes :

return ret.join('')

The problem is that when the items count is 0, options.inverse() is called on the context and replaces the return value.
But by default, when each has no else condition, it's a noop that does not return an array but an empty string, making ret.join() crash.

Handlebars does not have this problem because they don't have to join : https://github.com/handlebars-lang/handlebars.js/blob/785a63e0a84bc5d6617fd1619baa975f1380ddbd/lib/handlebars/helpers/each.js#L80

This solution works, for example:

image

@toverux toverux changed the title TypeError: ret.join is not a function "each" helper throws "TypeError: ret.join is not a function" when the context is an empty list Oct 20, 2022
evertonrobertoauler added a commit to evertonrobertoauler/handlebars-async-helpers that referenced this issue Jan 16, 2023
ericalli added a commit to ericalli/handlebars-async-helpers that referenced this issue May 13, 2023
@ericalli
Copy link
Contributor

I submitted PR #15 with the aforementioned fix and tests.

tobnieder added a commit to tobnieder/handlebars-async-helpers that referenced this issue Aug 29, 2023
gastonrobledo added a commit that referenced this issue Aug 30, 2023
Fixing issue #9 with tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants