Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the "safe" modifier to skip auto_escape #74

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions library/Rain/Tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function draw($templateFilePath, $toString = FALSE) {
extract($this->var);
// Merge local and static configurations
$this->config = $this->objectConf + static::$conf;

ob_start();
require $this->checkTemplate($templateFilePath);
$html = ob_get_clean();
Expand Down Expand Up @@ -533,9 +533,9 @@ protected function compileTemplate($code, $isString, $templateBasedir, $template
//get the included template
$includeTemplate = $actualFolder . $this->varReplace($matches[1], $loopLevel);

// reduce the path
// reduce the path
$includeTemplate = Tpl::reducePath( $includeTemplate );

//dynamic include
$parsedCode .= '<?php require $this->checkTemplate("' . $includeTemplate . '");?>';

Expand Down Expand Up @@ -695,7 +695,7 @@ protected function compileTemplate($code, $isString, $templateBasedir, $template
}
// registered tags
else {

$found = FALSE;
foreach (static::$registered_tags as $tags => $array) {
if (preg_match_all('/' . $array['parse'] . '/', $html, $matches)) {
Expand Down Expand Up @@ -764,11 +764,17 @@ protected function varReplace($html, $loopLevel = NULL, $escape = TRUE, $echo =
$html = str_replace($matches[0][$i], $rep, $html);
}

// add "safe" modifier to skip html escaping
if($this->config['auto_escape'] && $escape && !preg_match('/\$.*=.*/', $html) && (preg_match('/\|safe$/', $html) || preg_match('/\|safe\|/', $html))) {
$escape = false;
$html = preg_replace(array('/\|safe\|/', '/\|safe$/'), array('|', ''), $html);
}

// update modifier
$html = $this->modifierReplace($html);

// if does not initialize a value, e.g. {$a = 1}
if (!preg_match('/\$.*=.*/', $html)) {
if (!preg_match('/\$.*[^<>=!]=[^>].*/', $html)) {

// escape character
if ($this->config['auto_escape'] && $escape)
Expand All @@ -790,7 +796,7 @@ protected function conReplace($html) {
}

protected function modifierReplace($html) {

$this->blackList($html);
if (strpos($html,'|') !== false && substr($html,strpos($html,'|')+1,1) != "|") {
preg_match('/([\$a-z_A-Z0-9\(\),\[\]"->]+)\|([\$a-z_A-Z0-9\(\):,\[\]"->]+)/i', $html,$result);
Expand Down