|
|
@@ -164,8 +164,8 @@ class Mustache {
|
|
|
* @return string
|
|
|
*/
|
|
|
protected function _renderSection($template) {
|
|
|
- $otag = $this->_prepareRegEx($this->_otag);
|
|
|
- $ctag = $this->_prepareRegEx($this->_ctag);
|
|
|
+ $otag = preg_quote($this->_otag, '/');
|
|
|
+ $ctag = preg_quote($this->_ctag, '/');
|
|
|
$regex = '/' . $otag . '(\\^|\\#)\\s*(.+?)\\s*' . $ctag . '\\s*([\\s\\S]+?)' . $otag . '\\/\\s*\\2\\s*' . $ctag . '\\s*/m';
|
|
|
|
|
|
$matches = array();
|
|
|
@@ -227,8 +227,8 @@ class Mustache {
|
|
|
return $template;
|
|
|
}
|
|
|
|
|
|
- $otag = $this->_prepareRegEx($this->_otag);
|
|
|
- $ctag = $this->_prepareRegEx($this->_ctag);
|
|
|
+ $otag = preg_quote($this->_otag, '/');
|
|
|
+ $ctag = preg_quote($this->_ctag, '/');
|
|
|
$regex = '/' . $otag . '%\\s*([\\w_-]+)((?: [\\w]+=[\\w]+)*)\\s*' . $ctag . '\\n?/';
|
|
|
return preg_replace_callback($regex, array($this, '_renderPragma'), $template);
|
|
|
}
|
|
|
@@ -324,8 +324,11 @@ class Mustache {
|
|
|
return $template;
|
|
|
}
|
|
|
|
|
|
- $otag = $this->_prepareRegEx($this->_otag);
|
|
|
- $ctag = $this->_prepareRegEx($this->_ctag);
|
|
|
+ $otag_orig = $this->_otag;
|
|
|
+ $ctag_orig = $this->_ctag;
|
|
|
+
|
|
|
+ $otag = preg_quote($this->_otag, '/');
|
|
|
+ $ctag = preg_quote($this->_ctag, '/');
|
|
|
|
|
|
$this->_tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/";
|
|
|
|
|
|
@@ -342,6 +345,9 @@ class Mustache {
|
|
|
$template = substr($template, $offset + strlen($tag));
|
|
|
}
|
|
|
|
|
|
+ $this->_otag = $otag_orig;
|
|
|
+ $this->_ctag = $ctag_orig;
|
|
|
+
|
|
|
return $html . $template;
|
|
|
}
|
|
|
|
|
|
@@ -460,8 +466,8 @@ class Mustache {
|
|
|
$this->_otag = $tags[0];
|
|
|
$this->_ctag = $tags[1];
|
|
|
|
|
|
- $otag = $this->_prepareRegEx($this->_otag);
|
|
|
- $ctag = $this->_prepareRegEx($this->_ctag);
|
|
|
+ $otag = preg_quote($this->_otag, '/');
|
|
|
+ $ctag = preg_quote($this->_ctag, '/');
|
|
|
$this->_tagRegEx = '/' . $otag . "([#\^\/=!>\\{&])?(.+?)\\1?" . $ctag . "+/";
|
|
|
return '';
|
|
|
}
|
|
|
@@ -470,8 +476,8 @@ class Mustache {
|
|
|
* Push a local context onto the stack.
|
|
|
*
|
|
|
* @access protected
|
|
|
- * @param array $local_context
|
|
|
- * @return array
|
|
|
+ * @param array &$local_context
|
|
|
+ * @return void
|
|
|
*/
|
|
|
protected function _pushContext(&$local_context) {
|
|
|
$new = array();
|
|
|
@@ -537,11 +543,11 @@ class Mustache {
|
|
|
*
|
|
|
* @access protected
|
|
|
* @param string $tag_name
|
|
|
- * @param array &$context
|
|
|
+ * @param array $context
|
|
|
* @throws MustacheException Unknown variable name.
|
|
|
* @return string
|
|
|
*/
|
|
|
- protected function _findVariableInContext($tag_name, &$context) {
|
|
|
+ protected function _findVariableInContext($tag_name, $context) {
|
|
|
foreach ($context as $view) {
|
|
|
if (is_object($view)) {
|
|
|
if (isset($view->$tag_name)) {
|
|
|
@@ -593,22 +599,6 @@ class Mustache {
|
|
|
protected function _varIsIterable($var) {
|
|
|
return is_object($var) || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var))));
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Prepare a string to be used in a regular expression.
|
|
|
- *
|
|
|
- * @access protected
|
|
|
- * @param string $str
|
|
|
- * @return string
|
|
|
- */
|
|
|
- protected function _prepareRegEx($str) {
|
|
|
- $replace = array(
|
|
|
- '\\' => '\\\\', '^' => '\^', '.' => '\.', '$' => '\$', '|' => '\|', '(' => '\(',
|
|
|
- ')' => '\)', '[' => '\[', ']' => '\]', '*' => '\*', '+' => '\+', '?' => '\?',
|
|
|
- '{' => '\{', '}' => '\}', ',' => '\,'
|
|
|
- );
|
|
|
- return strtr($str, $replace);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|