From 4798e68f8843faf679a2080413b430631cee069c Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Wed, 24 May 2017 13:57:59 +0200 Subject: [PATCH] [CssRewriteFilter] Don't rewrite relative URLs beginning with hash (#) --- src/Assetic/Filter/CssRewriteFilter.php | 6 +++++- tests/Assetic/Test/Filter/CssRewriteFilterTest.php | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Assetic/Filter/CssRewriteFilter.php b/src/Assetic/Filter/CssRewriteFilter.php index c2250c3a4..763dd44c8 100644 --- a/src/Assetic/Filter/CssRewriteFilter.php +++ b/src/Assetic/Filter/CssRewriteFilter.php @@ -68,7 +68,11 @@ public function filterDump(AssetInterface $asset) } $content = $this->filterReferences($asset->getContent(), function ($matches) use ($host, $path) { - if (false !== strpos($matches['url'], '://') || 0 === strpos($matches['url'], '//') || 0 === strpos($matches['url'], 'data:')) { + if (false !== strpos($matches['url'], '://') + || 0 === strpos($matches['url'], '//') + || 0 === strpos($matches['url'], 'data:') + || '#' === substr($matches['url'], 0, 1) + ) { // absolute or protocol-relative or data uri return $matches[0]; } diff --git a/tests/Assetic/Test/Filter/CssRewriteFilterTest.php b/tests/Assetic/Test/Filter/CssRewriteFilterTest.php index 16c69358d..b7db4a947 100644 --- a/tests/Assetic/Test/Filter/CssRewriteFilterTest.php +++ b/tests/Assetic/Test/Filter/CssRewriteFilterTest.php @@ -61,6 +61,7 @@ public function provideUrls() array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', 'http://foo.com/bar.gif', 'http://foo.com/bar.gif'), array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', '/images/foo.gif', '/images/foo.gif'), array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', 'http://foo.com/images/foo.gif', 'http://foo.com/images/foo.gif'), + array('body { background: url(%s); }', 'css/body.css', 'css/build/main.css', '#foobar', '#foobar'), // IE AlphaImageLoader filter array('.fix { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'%s\'); }', 'css/ie.css', 'css/build/ie.css', '../images/fix.png', '../../images/fix.png'),