Browse Source

Fix greedy parsing of section name

Issue noticed for the transformation of a template for familywall.com,
using MustacheJS 0.3.0. In the anonymous function(match,type,name,content)
in render_section, the name of the section was incorrectly recognized as:

place}} <dd class="field"> <strong>{{#i18n

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

{{#place}} <dd class="field"> <strong>{{#i18n}}event.where_event_form{{/i18n}}</strong> <span class="hide" data-field="placeId">{{placeId}}</span> <span>{{name}}</span> </dd> {{/place}} <dd class="field"> <strong>{{#i18n}}

This is an unlikely bug, due to the use of the greedy operator + instead of
its non-greedy counterpart +?.
tags/0.4.1
Eric BRECHEMIER 14 years ago
parent
commit
01d01562e6
2 changed files with 5 additions and 1 deletions
  1. +4
    -0
      CHANGES.md
  2. +1
    -1
      mustache.js

+ 4
- 0
CHANGES.md View File

@@ -1,5 +1,9 @@
# mustache.js Changes

## 0.4.0-dev-familywall (2/9/2012)

* fixed greedy parsing of section name in regexp

## 0.4.0 (1/4/2012)

## 0.3.1-dev-twitter-b (8/23/2011)


+ 1
- 1
mustache.js View File

@@ -176,7 +176,7 @@ var Mustache = function () {
"^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1)

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

"\n*([\\s\\S]*?)" + // between the tag ($2). leading newlines are dropped


Loading…
Cancel
Save