mustache.java icon indicating copy to clipboard operation
mustache.java copied to clipboard

Mustache engine handles possibly invalid keynames in possibly incorrect way

Open simon-ess opened this issue 2 years ago • 1 comments

See https://github.com/mustache/spec/issues/179 for an issue raised on the mustache spec repository.

In brief, mustache.java renders the input data

{ "a.b": "c" }

and template

{{ a.b }}

as

c

which is in a perhaps-incorrect way, although one that is not actually specified by the spec. It is likely that keys are never intended to have periods in them (see https://github.com/mustache/spec/issues/67#issuecomment-53523219), but again, this is not actually specified.

Note that other engines, such as both of the python ones I have checked, render this as a blank.

Note further that the current java engine prioritises a key with a period over nested data: that is, the following data renders probably incorrectly (though again, not actually counter to the specification):

{ "a": { "b": "expected"}, "a.b": "c" }

and

{{ a.b }}

render as

c

which is not what I would expect.

simon-ess avatar Nov 21 '23 15:11 simon-ess

I think we are in unspecified behavior land. I shouldn't change the way this works as it would be backward incompatible. Seems like an edge case. If you absolutely need to have it work differently it would be straight-forward to override the ObjectHandler. Override findWrapper with a method that returns null if the name has a . in it.

spullara avatar Nov 21 '23 23:11 spullara