diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index ae04423a0..5f332f2ec 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -269,7 +269,7 @@ class TemplateHandler $buff = preg_replace('@@s', '', $buff); // replace value of src in img/input/script tag - $buff = preg_replace_callback('/<(?:img|input|script)(?:[^<>]*?)(?(?=cond=")(?:cond="[^"]+"[^<>]*)+|)[^<>]* src="(?!(?:https?|file):\/\/|[\/\{])([^"]+)"/is', array($this, '_replacePath'), $buff); + $buff = preg_replace_callback('/<(?:img|input|script)(?:[^<>]*?)(?(?=cond=")(?:cond="[^"]+"[^<>]*)+|)[^<>]* src="(?!(?:https?|file|data):|[\/\{])([^"]+)"/is', array($this, '_replacePath'), $buff); // replace value of srcset in img/source/link tag $buff = preg_replace_callback('/<(?:img|source|link)(?:[^<>]*?)(?(?=cond=")(?:cond="[^"]+"[^<>]*)+|)[^<>]* srcset="([^"]+)"/is', array($this, '_replaceSrcsetPath'), $buff); @@ -503,7 +503,7 @@ class TemplateHandler foreach ($url_list as &$url) { // replace if url is not starting with the pattern $url = preg_replace_callback( - '/^(?!(?:https?|file):\/\/|[\/\{])(\S+)/i', + '/^(?!(?:https?|file|data):|[\/\{])(\S+)/i', array($this, '_replaceRelativePath'), trim($url) ); diff --git a/tests/unit/classes/TemplateHandlerTest.php b/tests/unit/classes/TemplateHandlerTest.php index 9cc760020..d2a4ba124 100644 --- a/tests/unit/classes/TemplateHandlerTest.php +++ b/tests/unit/classes/TemplateHandlerTest.php @@ -282,6 +282,10 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test 'asdf src="../img/img.gif" asdf', '?>asdf src="../img/img.gif" asdf' ), + array( + '', + '?>' + ), // srcset (PR #1544) array( 'this is a test image.',