From 9b8454f2ba0a0628af8d3ae1d39fb955856aa916 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 26 Apr 2010 22:38:33 -0400 Subject: [PATCH] Simplified tag RegEx. Fixed bug preventing section modifiers inside comments. --- Mustache.php | 5 +++-- examples/comments/comments.mustache | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Mustache.php b/Mustache.php index e1f69cd..48b4e1b 100644 --- a/Mustache.php +++ b/Mustache.php @@ -177,7 +177,7 @@ class Mustache { $otag = $this->prepareRegEx($this->otag); $ctag = $this->prepareRegEx($this->ctag); - $this->tagRegEx = '/' . $otag . "(#|\/|=|!|>|\\{|&)?([^\/#]+?)\\1?" . $ctag . "+/"; + $this->tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/"; $html = ''; $matches = array(); while (preg_match($this->tagRegEx, $template, $matches, PREG_OFFSET_CAPTURE)) { @@ -210,6 +210,7 @@ class Mustache { protected function renderTag($modifier, $tag_name, &$context) { switch ($modifier) { case '#': + case '^': if ($this->throwSectionExceptions) { throw new MustacheException('Unclosed section: ' . $tag_name, MustacheException::UNCLOSED_SECTION); } else { @@ -310,7 +311,7 @@ class Mustache { $otag = $this->prepareRegEx($this->otag); $ctag = $this->prepareRegEx($this->ctag); - $this->tagRegEx = '/' . $otag . "(#|\/|=|!|>|\\{|&)?([^\/#\^]+?)\\1?" . $ctag . "+/"; + $this->tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/"; return ''; } diff --git a/examples/comments/comments.mustache b/examples/comments/comments.mustache index b6feac8..846e449 100644 --- a/examples/comments/comments.mustache +++ b/examples/comments/comments.mustache @@ -1 +1 @@ -

{{title}}{{! just something interesting... or not... }}

\ No newline at end of file +

{{title}}{{! just something interesting... #or ^not... }}

\ No newline at end of file