From 37cf2706a96c70a5849288743622d4cb59a2fbde Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 30 Apr 2010 00:15:17 -0400 Subject: [PATCH] Allow whitespace in pragma tags. --- Mustache.php | 2 +- test/MustachePragmaTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 8e87331..119d120 100644 --- a/Mustache.php +++ b/Mustache.php @@ -199,7 +199,7 @@ class Mustache { $otag = $this->prepareRegEx($this->otag); $ctag = $this->prepareRegEx($this->ctag); - $regex = '/' . $otag . '%([\\w_-]+)((?: [\\w]+=[\\w]+)*)' . $ctag . '\\n?/'; + $regex = '/' . $otag . '%\\s*([\\w_-]+)((?: [\\w]+=[\\w]+)*)\\s*' . $ctag . '\\n?/'; return preg_replace_callback($regex, array($this, 'renderPragma'), $template); } diff --git a/test/MustachePragmaTest.php b/test/MustachePragmaTest.php index db21269..534aab3 100644 --- a/test/MustachePragmaTest.php +++ b/test/MustachePragmaTest.php @@ -25,6 +25,8 @@ class MustachePragmaTest extends PHPUnit_Framework_TestCase { public function testPragmaReplaceMultiple() { $m = new Mustache(); + $this->assertEquals('', $m->render('{{% DOT-NOTATION }}'), 'Pragmas should allow whitespace'); + $this->assertEquals('', $m->render('{{% DOT-NOTATION foo=bar }}'), 'Pragmas should allow whitespace'); $this->assertEquals($m->render("{{%DOT-NOTATION}}\n{{%DOT-NOTATION}}"), '', 'Multiple pragma tags not removed'); $this->assertEquals($m->render('{{%DOT-NOTATION}} {{%DOT-NOTATION}}'), ' ', 'Multiple pragma tags not removed'); }