From 0130ab64936dc51b0ab50d7c1b0c4b79b2302982 Mon Sep 17 00:00:00 2001 From: bnu Date: Thu, 4 Jun 2015 17:08:24 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#1510=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=83=81=EB=8C=80=EA=B2=BD=EB=A1=9C=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/template/TemplateHandler.class.php | 10 +++++----- .../classes/template/TemplateHandlerTest.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index 831686b77..b16597e36 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -236,7 +236,7 @@ class TemplateHandler $buff = preg_replace('@@s', '', $buff); // replace value of src in img/input/script tag - $buff = preg_replace_callback('/<(?:img|input|script)(?(?=[[:space:]]+?cond=")[[:space:]]+?cond="[^"]+"|)[^<>]*[[:space:]]src="(?!https?:\/\/|[\/\{])([^"]+)"/is', array($this, '_replacePath'), $buff); + $buff = preg_replace_callback('/(<(?:img|input|script).+src=")(?!(?:https?|file):\/\/|[\/\{])([^"]+)("[^>]+>)/is', array($this, '_replacePath'), $buff); // replace loop and cond template syntax $buff = $this->_parseInline($buff); @@ -415,18 +415,18 @@ class TemplateHandler private function _replacePath($match) { //return origin conde when src value started '${'. - if(preg_match('@^\${@', $match[1])) + if(preg_match('@^\${@', $match[2])) { return $match[0]; } //return origin code when src value include variable. - if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) + if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[2])) { return $match[0]; } - $src = preg_replace('@^(\./)+@', '', trim($match[1])); + $src = preg_replace('@^(\./)+@', '', trim($match[2])); $src = $this->web_path . $src; $src = str_replace('/./', '/', $src); @@ -439,7 +439,7 @@ class TemplateHandler $src = $tmp; } - return substr($match[0], 0, -strlen($match[1]) - 6) . "src=\"{$src}\""; + return $match[1] . $src . $match[3]; } /** diff --git a/tests/unit/classes/template/TemplateHandlerTest.php b/tests/unit/classes/template/TemplateHandlerTest.php index 424537a28..94e1c0e32 100644 --- a/tests/unit/classes/template/TemplateHandlerTest.php +++ b/tests/unit/classes/template/TemplateHandlerTest.php @@ -245,6 +245,24 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test '', PHP_EOL . 'if($__Context->foo->bar){ ?>' ), + // https://github.com/xpressengine/xe-core/issues/1510 + array( + '', + PHP_EOL . 'if(!$__Context->module_info->title){ ?>' + ), + // https://github.com/xpressengine/xe-core/issues/1510 + array( + '', + PHP_EOL . 'if($__Context->mi->title){ ?>mi->use){ ?> class="tmp_class" src="/xe/tests/unit/classes/img/common/blank.gif" />' + ), + array( + ' alt', + '?> foo->bar){ ?>alt' + ), + array( + 'asf ', + '?>asf ' + ), ); }