noahmorrison / chevron

A Python implementation of mustache
MIT License
480 stars 52 forks source link

Chevron does not match other implementations with nested arrays #85

Open ergoithz opened 3 years ago

ergoithz commented 3 years ago

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/

dmorrison42 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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