From 758027bd9113a8ee9ebb45c3ec78d73c4803b031 Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Tue, 17 Aug 2010 10:53:19 -0500 Subject: [PATCH 1/7] Fixing Issue #11 --- Mustache.php | 2 +- examples/simple/Simple.php | 1 + examples/simple/simple.mustache | 2 +- examples/simple/simple.txt | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Mustache.php b/Mustache.php index 2b7551c..60e66c8 100644 --- a/Mustache.php +++ b/Mustache.php @@ -469,7 +469,7 @@ class Mustache { * @return string */ protected function _renderEscaped($tag_name) { - return htmlentities($this->_getVariable($tag_name), null, $this->_charset); + return htmlentities($this->_getVariable($tag_name), ENT_COMPAT, $this->_charset); } /** diff --git a/examples/simple/Simple.php b/examples/simple/Simple.php index 6d07dac..86b5674 100644 --- a/examples/simple/Simple.php +++ b/examples/simple/Simple.php @@ -2,6 +2,7 @@ class Simple extends Mustache { public $name = "Chris"; + public $last_name = '"Bob"'; public $value = 10000; public function taxed_value() { diff --git a/examples/simple/simple.mustache b/examples/simple/simple.mustache index 03df206..4b73537 100644 --- a/examples/simple/simple.mustache +++ b/examples/simple/simple.mustache @@ -1,4 +1,4 @@ -Hello {{name}} +Hello {{name}} {{last_name}} You have just won ${{value}}! {{#in_ca}} Well, ${{ taxed_value }}, after taxes. diff --git a/examples/simple/simple.txt b/examples/simple/simple.txt index 5d75d65..a7c7b13 100644 --- a/examples/simple/simple.txt +++ b/examples/simple/simple.txt @@ -1,3 +1,3 @@ -Hello Chris +Hello Chris "Bob" You have just won $10000! Well, $6000, after taxes. From e3c7afde46d5dbf7c86b0d954b79b955549ec42b Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 17 Aug 2010 15:27:46 -0400 Subject: [PATCH 2/7] Moved test for #11 into 'escaped' example. --- examples/escaped/Escaped.php | 2 +- examples/escaped/escaped.txt | 2 +- examples/simple/Simple.php | 1 - examples/simple/simple.mustache | 2 +- examples/simple/simple.txt | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/escaped/Escaped.php b/examples/escaped/Escaped.php index e6605bc..2852196 100644 --- a/examples/escaped/Escaped.php +++ b/examples/escaped/Escaped.php @@ -1,5 +1,5 @@ Shark"; + public $title = '"Bear" > "Shark"'; } \ No newline at end of file diff --git a/examples/escaped/escaped.txt b/examples/escaped/escaped.txt index dcab18d..6ba3657 100644 --- a/examples/escaped/escaped.txt +++ b/examples/escaped/escaped.txt @@ -1 +1 @@ -

Bear > Shark

\ No newline at end of file +

"Bear" > "Shark"

\ No newline at end of file diff --git a/examples/simple/Simple.php b/examples/simple/Simple.php index 86b5674..6d07dac 100644 --- a/examples/simple/Simple.php +++ b/examples/simple/Simple.php @@ -2,7 +2,6 @@ class Simple extends Mustache { public $name = "Chris"; - public $last_name = '"Bob"'; public $value = 10000; public function taxed_value() { diff --git a/examples/simple/simple.mustache b/examples/simple/simple.mustache index 4b73537..03df206 100644 --- a/examples/simple/simple.mustache +++ b/examples/simple/simple.mustache @@ -1,4 +1,4 @@ -Hello {{name}} {{last_name}} +Hello {{name}} You have just won ${{value}}! {{#in_ca}} Well, ${{ taxed_value }}, after taxes. diff --git a/examples/simple/simple.txt b/examples/simple/simple.txt index a7c7b13..5d75d65 100644 --- a/examples/simple/simple.txt +++ b/examples/simple/simple.txt @@ -1,3 +1,3 @@ -Hello Chris "Bob" +Hello Chris You have just won $10000! Well, $6000, after taxes. From e8f99bb04e494265ba78670156951696b3f40bcb Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Sat, 2 Oct 2010 21:05:37 +0100 Subject: [PATCH 3/7] Use array_key_exists instead of isset for checking array values. --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 2b7551c..35377e8 100644 --- a/Mustache.php +++ b/Mustache.php @@ -608,7 +608,7 @@ class Mustache { } else if (isset($view->$tag_name)) { return $view->$tag_name; } - } else if (isset($view[$tag_name])) { + } else if (array_key_exists ($tag_name, $view)) { return $view[$tag_name]; } } From 65770a03f65fc2fea05c3d3c4af4aa06deffbbf4 Mon Sep 17 00:00:00 2001 From: Neuman Vong Date: Fri, 29 Oct 2010 14:05:55 -0700 Subject: [PATCH 4/7] Use is_callable instead of method_exists To use objects implementing __call(). Closes #18. --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 2b7551c..da79733 100644 --- a/Mustache.php +++ b/Mustache.php @@ -603,7 +603,7 @@ class Mustache { protected function _findVariableInContext($tag_name, $context) { foreach ($context as $view) { if (is_object($view)) { - if (method_exists($view, $tag_name)) { + if (is_callable(array($view, $tag_name))) { return $view->$tag_name(); } else if (isset($view->$tag_name)) { return $view->$tag_name; From f3cb0877ffde97b7278a8c03725242eac5d835e6 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 30 Oct 2010 16:53:14 -0400 Subject: [PATCH 5/7] Add support for 'less-than' partial notation. --- Mustache.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Mustache.php b/Mustache.php index 60e66c8..4d8b492 100644 --- a/Mustache.php +++ b/Mustache.php @@ -385,7 +385,7 @@ class Mustache { $otag = preg_quote($this->_otag, '/'); $ctag = preg_quote($this->_ctag, '/'); - $this->_tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/s"; + $this->_tagRegEx = '/' . $otag . "([#\^\/=!<>\\{&])?(.+?)\\1?" . $ctag . "+/s"; $html = ''; $matches = array(); @@ -442,6 +442,7 @@ class Mustache { return $this->_renderComment($tag_name); break; case '>': + case '<': return $this->_renderPartial($tag_name); break; case '{': @@ -521,7 +522,7 @@ class Mustache { $otag = preg_quote($this->_otag, '/'); $ctag = preg_quote($this->_ctag, '/'); - $this->_tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/s"; + $this->_tagRegEx = '/' . $otag . "([#\^\/=!<>\\{&])?(.+?)\\1?" . $ctag . "+/s"; return ''; } From f2d77ad6955df90dd1175d5947b6408278cf91dc Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 30 Oct 2010 17:13:27 -0400 Subject: [PATCH 6/7] Whitespace --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 35377e8..2766e15 100644 --- a/Mustache.php +++ b/Mustache.php @@ -608,7 +608,7 @@ class Mustache { } else if (isset($view->$tag_name)) { return $view->$tag_name; } - } else if (array_key_exists ($tag_name, $view)) { + } else if (array_key_exists($tag_name, $view)) { return $view[$tag_name]; } } From 35c725089be88d7a044a109a2d9cea594b6eb1dd Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 30 Oct 2010 18:06:39 -0400 Subject: [PATCH 7/7] Revert "Merge branch 'luciferous-master' into dev" This reverts commit 9202a37cf517a24b17fb554adbab5c6bfbb227bd, reversing changes made to 54b5800d420da0dea307fa79518f181f3dbe5554. Using `is_callable` is problematic as the `__call` magic method interferes with context all over the place. See http://hile.mn/buBS11 and http://hile.mn/9vy1S6 --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index a8abf74..4fded45 100644 --- a/Mustache.php +++ b/Mustache.php @@ -604,7 +604,7 @@ class Mustache { protected function _findVariableInContext($tag_name, $context) { foreach ($context as $view) { if (is_object($view)) { - if (is_callable(array($view, $tag_name))) { + if (method_exists($view, $tag_name)) { return $view->$tag_name(); } else if (isset($view->$tag_name)) { return $view->$tag_name;