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

Chevron does not match other implementations with nested arrays #85

Open
ergoithz opened this issue Dec 18, 2020 · 3 comments
Open

Chevron does not match other implementations with nested arrays #85

ergoithz opened this issue Dec 18, 2020 · 3 comments

Comments

@ergoithz
Copy link

ergoithz commented Dec 18, 2020

Chevron does not seem to enter scope with nested empty lists, which is non-compliant with spec

Given this example:

{"arrays": [[1,2,3], []]}
{{#arrays}}
[{{#.}}{{.}}{{/.}}] is {{^.}}empty{{/.}}{{#0}}non empty{{/0}}
{{/arrays}}

chevron output

[123] is non empty

expectation (validated with ruby mustache, mustache.js, handlebars.js and others)

[123] is non empty
[] is empty

I'm not expecting this to be fixed or anything, we all know this is project is abandoned, just droping this issue here for anyone reading that chevron is spec compliant from the README.

Code

python

import chevron

template = """
{{#arrays}}
[{{#.}}{{.}}{{/.}}] is {{^.}}empty{{/.}}{{#0}}non empty{{/0}}
{{/arrays}}
""".strip()
data = {"arrays": [[1,2,3], []]}
print(chevron.render(template, data))

ruby

require 'mustache'

print Mustache.render(
    "{{#arrays}}\n" \
    "[{{#.}}{{.}}{{/.}}] is {{^.}}empty{{/.}}{{#0}}non empty{{/0}}\n" \
    "{{/arrays}}", arrays: [[1, 2, 3], []])

JavaScript tested with http://mustache.github.io/#demo and http://tryhandlebarsjs.com/

@ergoithz ergoithz changed the title Chevron IS NOT spec compliant (empty nested array) Chevron IS NOT spec compliant with arrays Dec 19, 2020
@ergoithz ergoithz changed the title Chevron IS NOT spec compliant with arrays Chevron IS NOT spec compliant with nested arrays Dec 19, 2020
@dmorrison42
Copy link
Contributor

The mustache spec was finished before this project was started, and there are many areas in the specification that could be improved (see the issues here https://github.com/mustache/spec, and the numerous chevron specific tests). If there are tests from the specification that aren't being run please just point out which one and chevron's test runner can be updated.

That being said this does seem like a reasonable change request. A different mustache implementation having specific handling is a good argument for a change in the mustache spec, or more realistically for it to be added to the existing set of chevron specific tests.

I believe that you are saying that empty arrays should be truthy, and that your evidences are the ruby, javascript, and handlebars implementations.

@noahmorrison noahmorrison changed the title Chevron IS NOT spec compliant with nested arrays Chevron does not match other implementations with nested arrays Jan 2, 2021
@noahmorrison
Copy link
Owner

Spec compliance means it passes the spec unit tests. Which to my knowledge I do in every python version 2.6 and above (if I don't, it's a bug and I'll try to fix it).

This is a feature request, because you want me to implement a behavior that is not specified in the spec, but is how other implementations of mustache handle it. I'm not opposed to feature requests like these, and I've implemented them before.

I've changed the title to reflect this, and I'll get to this after I've handled the other open issues.

@dmorrison42
Copy link
Contributor

Actually, I think this is a duplicate of #57.

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