Skip to content

Commit

Permalink
Work in progress. Fixing double-rendering of sections, mustache injec…
Browse files Browse the repository at this point in the history
…tion, etc.
  • Loading branch information
bobthecow committed Jun 13, 2011
1 parent 61a0b7f commit 9af6b20
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions Mustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,10 @@ public function __toString() {
* @return string Rendered Mustache template.
*/
protected function _renderTemplate($template) {
$template = $this->_renderSections($template);
return $this->_renderTags($template);
}

/**
* Render boolean, enumerable and inverted sections.
*
* @access protected
* @param string $template
* @return string
*/
protected function _renderSections($template) {
while ($section_data = $this->_findSection($template)) {
list($section, $offset, $type, $tag_name, $content) = $section_data;
if ($section = $this->_findSection($template)) {
list($section, $offset, $type, $tag_name, $content) = $section;
$before = substr($template, 0, $offset);
$after = substr($template, $offset + strlen($section));

$replace = '';
$val = $this->_getVariable($tag_name);
Expand Down Expand Up @@ -256,10 +246,10 @@ protected function _renderSections($template) {
break;
}

$template = substr_replace($template, $replace, $offset, strlen($section));
return $this->_renderTags($before) . $replace . $this->_renderTemplate($after);
}

return $template;
return $this->_renderTags($template);
}

/**
Expand Down Expand Up @@ -856,4 +846,4 @@ class MustacheException extends Exception {
// which can't be handled by this Mustache instance.
const UNKNOWN_PRAGMA = 4;

}
}

0 comments on commit 9af6b20

Please sign in to comment.