mustache / spec

The Mustache spec.
MIT License
368 stars 71 forks source link

Define syntax of tag names #67

Open Abscissa opened 11 years ago

Abscissa commented 11 years ago

There doesn't appear to be any defined spec for the syntax of tag names. For example: can they include embedded whitespace? Which non-alpha-numeric symbols can/can't they include? Is empty-sting allowed as a name (the syntax does make this possible, but is it allowed)? Etc.

bobthecow commented 10 years ago

I would read the spec as allowing anything not explicitly disallowed. In fact, whitespace, ->, and all sorts of reserved-looking characters are perfectly valid in identifiers or map keys in many languages. Artificially restricting allowed characters would make things harder for users of those languages to get data into their templates, and would have little benefit.

The only things that a tag name can't contain are . and the closing delimiter (and they can't start with any of the tag sigils — &, =, >, etc — unless they're inside a tag that already has a sigil, so I'd avoid starting with them regardless).

(Quoting myself, from defunkt/pystache#156)

groue commented 10 years ago

@bobthecow is right.

Let's add that white space in tag names should be avoided.

If they were not, spaces surrounding names and spaces inside names would behave differently. Using the dash to show white space:

This is a serious enough issue to prevent white space in tag names.

The prevention of tag sigils at the beginning of names is driven by the same concern. A Mustache implementation has to actively prevent users to believe that {{ >name }} is a partial tag, and {{{#name}}}...{{{/name}}} an "unescaped section".

The prevention of dots is required by compound expression such as user.name.

So, the spec is lacking when it does not make all of this explicit. Fortunately, there are years of implementors experience.