1
0
mirror of https://github.com/mrclay/minify.git synced 2025-01-17 13:18:13 +01:00

Merge pull request #563 from mrclay/561_empty_url

URI rewriter passes through empty URLs
This commit is contained in:
Steve Clay 2017-01-18 21:01:09 -05:00 committed by GitHub
commit a07991c052
5 changed files with 13 additions and 0 deletions

View File

@ -294,6 +294,11 @@ class Minify_CSS_UriRewriter
$uri = ($quoteChar === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2); $uri = ($quoteChar === '') ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2);
} }
if ($uri === '') {
return $m[0];
}
// if not root/scheme relative and not starts with scheme // if not root/scheme relative and not starts with scheme
if (!preg_match('~^(/|[a-z]+\:)~', $uri)) { if (!preg_match('~^(/|[a-z]+\:)~', $uri)) {
// URI is file-relative: rewrite depending on options // URI is file-relative: rewrite depending on options

View File

@ -8,6 +8,7 @@
@import url("/css/foo.css"); /* abs, should not alter */ @import url("/css/foo.css"); /* abs, should not alter */
@import url(/css2/foo.css); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */
@import url(foo:bar); /* scheme, should not alter */ @import url(foo:bar); /* scheme, should not alter */
@import url(); /* empty, should not alter */
foo {clip-path:url(#c1)} /* inline clip path, should not alter */ foo {clip-path:url(#c1)} /* inline clip path, should not alter */
foo {clip-path:url(/_test_files/css_uriRewriter/foo.svg#c1)} foo {clip-path:url(/_test_files/css_uriRewriter/foo.svg#c1)}
foo {mask: url(#c1)} /* should not alter */ foo {mask: url(#c1)} /* should not alter */
@ -17,5 +18,6 @@ foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("/_test_files/css_uriRewriter/foo bar.jpg");} foo {background:url("/_test_files/css_uriRewriter/foo bar.jpg");}
foo {background:url("");} /* empty, should not alter */
@import url('/_test_files/css_uriRewriter/foo bar.css'); @import url('/_test_files/css_uriRewriter/foo bar.css');
@import "/_test_files/css_uriRewriter/foo bar.css"; @import "/_test_files/css_uriRewriter/foo bar.css";

View File

@ -8,6 +8,7 @@
@import url("/css/foo.css"); /* abs, should not alter */ @import url("/css/foo.css"); /* abs, should not alter */
@import url(/css2/foo.css); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */
@import url(foo:bar); /* scheme, should not alter */ @import url(foo:bar); /* scheme, should not alter */
@import url(); /* empty, should not alter */
foo {clip-path:url(#c1)} /* inline clip path, should not alter */ foo {clip-path:url(#c1)} /* inline clip path, should not alter */
foo {clip-path:url(http://cnd.com/A/B/foo.svg#c1)} foo {clip-path:url(http://cnd.com/A/B/foo.svg#c1)}
foo {mask: url(#c1)} /* should not alter */ foo {mask: url(#c1)} /* should not alter */
@ -17,5 +18,6 @@ foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("http://cnd.com/A/B/foo bar.jpg");} foo {background:url("http://cnd.com/A/B/foo bar.jpg");}
foo {background:url("");} /* empty, should not alter */
@import url('http://cnd.com/A/B/foo bar.css'); @import url('http://cnd.com/A/B/foo bar.css');
@import "http://cnd.com/A/B/foo bar.css"; @import "http://cnd.com/A/B/foo bar.css";

View File

@ -8,6 +8,7 @@
@import url("/css/foo.css"); /* abs, should not alter */ @import url("/css/foo.css"); /* abs, should not alter */
@import url(/css2/foo.css); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */
@import url(foo:bar); /* scheme, should not alter */ @import url(foo:bar); /* scheme, should not alter */
@import url(); /* empty, should not alter */
foo {clip-path:url(#c1)} /* inline clip path, should not alter */ foo {clip-path:url(#c1)} /* inline clip path, should not alter */
foo {clip-path:url(//cnd.com/A/B/foo.svg#c1)} foo {clip-path:url(//cnd.com/A/B/foo.svg#c1)}
foo {mask: url(#c1)} /* should not alter */ foo {mask: url(#c1)} /* should not alter */
@ -17,5 +18,6 @@ foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("//cnd.com/A/B/foo bar.jpg");} foo {background:url("//cnd.com/A/B/foo bar.jpg");}
foo {background:url("");} /* empty, should not alter */
@import url('//cnd.com/A/B/foo bar.css'); @import url('//cnd.com/A/B/foo bar.css');
@import "//cnd.com/A/B/foo bar.css"; @import "//cnd.com/A/B/foo bar.css";

View File

@ -8,6 +8,7 @@
@import url("/css/foo.css"); /* abs, should not alter */ @import url("/css/foo.css"); /* abs, should not alter */
@import url(/css2/foo.css); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */
@import url(foo:bar); /* scheme, should not alter */ @import url(foo:bar); /* scheme, should not alter */
@import url(); /* empty, should not alter */
foo {clip-path:url(#c1)} /* inline clip path, should not alter */ foo {clip-path:url(#c1)} /* inline clip path, should not alter */
foo {clip-path:url(foo.svg#c1)} foo {clip-path:url(foo.svg#c1)}
foo {mask: url( #c1 )} /* should not alter */ foo {mask: url( #c1 )} /* should not alter */
@ -17,5 +18,6 @@ foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
foo {background:url(foo:bar);} /* scheme, should not alter */ foo {background:url(foo:bar);} /* scheme, should not alter */
foo {background:url("foo bar.jpg");} foo {background:url("foo bar.jpg");}
foo {background:url("");} /* empty, should not alter */
@import url('foo bar.css'); @import url('foo bar.css');
@import "foo bar.css"; @import "foo bar.css";