janl/mustache.js — Issue #162: Greedy section parsing, RegExp issue up to version 0.4.0
Author: eric-brechemier
Created: 2012-02-09 12:28:28+00:00
State: open

Issue noticed in MustacheJS 0.3.0 during the development of familywall.com, also present in 0.4.0.

In the anonymous function(match,type,name,content) in render_section, the name of the section is incorrectly recognized as:

place}}
{{#i18n

within a match where the same string is repeated after a / at the end:

{{#place}}
{{#i18n}}event.where_event_form{{/i18n}} {{placeId}} {{name}}
{{/place}}
{{#i18n}}

This is an unlikely bug, due to the use of the greedy operator + instead of its non-greedy counterpart +?:

- "(\\^|\\#)\\s*(.+)\\s*" + // #foo (# == $2, foo == $3)
+ "(\\^|\\#)\\s*(.+?)\\s*" +// #foo (# == $2, foo == $3), not greedy

I created a maintenance branch forked from 0.4.0, with a fix for this issue tagged "0.4.0-dev-familywall":
https://github.com/eric-brechemier/mustache.js/tree/0.4.0-dev-familywall