From a4f989742344ac6d793d30447bd188efd848503c Mon Sep 17 00:00:00 2001 From: bnu Date: Thu, 4 Jun 2015 17:51:40 +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 | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index b16597e36..84946b333 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).+src=")(?!(?:https?|file):\/\/|[\/\{])([^"]+)("[^>]+>)/is', array($this, '_replacePath'), $buff); + $buff = preg_replace_callback('/<(?:img|input|script)(?:[^<>]*?)(?(?=cond=")(?:cond="[^"]+"[^<>]*)+|)[^<>]* 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[2])) + if(preg_match('@^\${@', $match[1])) { return $match[0]; } //return origin code when src value include variable. - if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[2])) + if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1])) { return $match[0]; } - $src = preg_replace('@^(\./)+@', '', trim($match[2])); + $src = preg_replace('@^(\./)+@', '', trim($match[1])); $src = $this->web_path . $src; $src = str_replace('/./', '/', $src); @@ -439,7 +439,7 @@ class TemplateHandler $src = $tmp; } - return $match[1] . $src . $match[3]; + return substr($match[0], 0, -strlen($match[1]) - 6) . "src=\"{$src}\""; } /** diff --git a/tests/unit/classes/template/TemplateHandlerTest.php b/tests/unit/classes/template/TemplateHandlerTest.php index 94e1c0e32..daece9612 100644 --- a/tests/unit/classes/template/TemplateHandlerTest.php +++ b/tests/unit/classes/template/TemplateHandlerTest.php @@ -259,10 +259,26 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test ' alt', '?> foo->bar){ ?>alt' ), + array( + '' . "\n" . ' alt', + '?>' . PHP_EOL . ' foo->bar){ ?>alt' + ), array( 'asf ', '?>asf ' ), + array( + '', + '?>' + ), + array( + 'asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf', + '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' + ), + array( + 'asdf src="../img/img.gif" asdf', + '?>asdf src="../img/img.gif" asdf' + ), ); }