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

String.length in lookup #589

Closed
Eliak opened this issue Aug 12, 2016 · 2 comments
Closed

String.length in lookup #589

Eliak opened this issue Aug 12, 2016 · 2 comments

Comments

@Eliak
Copy link

Eliak commented Aug 12, 2016

Mustache.render('{{#list}}{{a.length}}{{/list}}', {list: [{a: 'a'}]}) === ""
When: Mustache.render('{{a.length}}', {a: 'a'}) === "1"

@dasilvacontin
Copy link
Collaborator

dasilvacontin commented Aug 16, 2016

Afaik {{a.length}} should render as '' in both cases.

Thanks for reporting!

@raymond-lam
Copy link
Contributor

I believe this is actually a particular manifestation of a more general bug. See PR #618

phillipj pushed a commit that referenced this issue Aug 25, 2018
)

* prevent value from being returned by Context.prototype.lookup if lookupHit is false

* add test for renderability of Array.length via dot notation

* Remove `typeof obj === 'object'` constraint in prop lookup

Allows rendering properties of primitive types that are not objects, such as a string.

* pop lookup needs to use hasOwnProperty for non-objs

* re-add  constraint in prop lookup, but make property lookups for primitives possible through dot notation

* add test to address #589 specifically

* enhance readability of primitiveHasOwnProperty and add comments to explain why it is used in one case but not the other
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

3 participants