diff --git a/examples/two_sections.html b/examples/two_sections.html
index cc54add..356ea66 100644
--- a/examples/two_sections.html
+++ b/examples/two_sections.html
@@ -1,7 +1,7 @@
-{{#show_following}}
-
-{{/show_following}}
-{{#show_following}}
-
-{{/show_following}}
-
+{{#foo}}
+ BAR
+{{/foo}}
+BAR
+{{^bar}}
+ BAR
+{{/bar}}
diff --git a/examples/two_sections.js b/examples/two_sections.js
index 8546f64..bbd9cb9 100644
--- a/examples/two_sections.js
+++ b/examples/two_sections.js
@@ -1 +1,4 @@
-var two_sections = {};
\ No newline at end of file
+var two_sections = {
+ foo: true,
+ bar: false
+};
\ No newline at end of file
diff --git a/examples/two_sections.txt b/examples/two_sections.txt
index c634376..8a62495 100644
--- a/examples/two_sections.txt
+++ b/examples/two_sections.txt
@@ -1,3 +1,3 @@
- BAR bar
- BAR bar
- BAR bar
+ BAR
+BAR
+ BAR
diff --git a/mustache.js b/mustache.js
index 0e9719c..3eb294d 100644
--- a/mustache.js
+++ b/mustache.js
@@ -149,7 +149,7 @@ var Mustache = function() {
var that = this;
var regex = new RegExp("(?:^([\\s\\S]*?))?" + this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag +
- "\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\3\\s*" + this.ctag + "\\s*" +
+ "\n*([\\s\\S]*?)" + this.otag + "\\/\\s*\\3\\s*" + this.ctag + "\\s*" +
"([\\s\\S]*?)(?=(?:" + this.otag + "(?:\\^|\\#)\\s*(?:.+)\\s*" + this.ctag + ")|$)", "g");
// for each {{#foo}}{{/foo}} section do...
diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb
index 6656703..b4067a3 100644
--- a/test/mustache_spec.rb
+++ b/test/mustache_spec.rb
@@ -92,22 +92,18 @@ describe "mustache" do
run_js(js).strip.should == "foo BAR"
end
- it "should not suck" do
+ it "should work with empty sections" do
js = <<-JS
try{
#{@boilerplate}
- print(Mustache.to_html("{{#foo}}\\
-{{/foo}}\\
-{{#bar}}\\
-{{/bar}}\\
-", {}));
+ print(Mustache.to_html("{{#foo}}{{/foo}}foo{{#bar}}{{/bar}}", {}));
} catch(e) {
print(e);
}
JS
- run_js(js).should == "foanfs"
+ run_js(js).strip.should == "foo"
end