From 01d01562e6cc6e05b6b449b73bb0a2ee2a3f9209 Mon Sep 17 00:00:00 2001 From: Eric BRECHEMIER Date: Thu, 9 Feb 2012 13:10:23 +0100 Subject: [PATCH] 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}}
{{#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 +?. --- CHANGES.md | 4 ++++ mustache.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a9994d2..fe64aac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/mustache.js b/mustache.js index 91ec828..feb2913 100644 --- a/mustache.js +++ b/mustache.js @@ -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