From 143046d47289268d3ffa6029a35c7bfc34d37f34 Mon Sep 17 00:00:00 2001 From: Joe Cai Date: Thu, 2 Jan 2014 11:27:40 +0800 Subject: [PATCH 1/4] CSS_UriRewriter: do not rewrite about:blank --- min/lib/Minify/CSS/UriRewriter.php | 1 + min_unit_tests/_test_files/css_uriRewriter/exp.css | 4 +++- min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css | 4 +++- min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css | 2 +- min_unit_tests/_test_files/css_uriRewriter/in.css | 4 +++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/min/lib/Minify/CSS/UriRewriter.php b/min/lib/Minify/CSS/UriRewriter.php index 8845f15..e1c67ed 100644 --- a/min/lib/Minify/CSS/UriRewriter.php +++ b/min/lib/Minify/CSS/UriRewriter.php @@ -284,6 +284,7 @@ class Minify_CSS_UriRewriter { } // analyze URI if ('/' !== $uri[0] // root-relative + && 0 !== strpos($uri, 'about:blank') //about:blank && false === strpos($uri, '//') // protocol (non-data) && 0 !== strpos($uri, 'data:') // data protocol ) { diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp.css b/min_unit_tests/_test_files/css_uriRewriter/exp.css index d749295..8a30a2d 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp.css @@ -11,4 +11,6 @@ foo {background:url('/_test_files/css_uriRewriter/bar/foo.png')} foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ -foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ \ No newline at end of file +foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ +foo {background:url(about:blank);} /* about:blank, should not alter */ +foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css index 87b7ecb..251c593 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css @@ -11,4 +11,6 @@ foo {background:url('http://cnd.com/A/B/bar/foo.png')} foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ -foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ \ No newline at end of file +foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ +foo {background:url(about:blank);} /* about:blank, should not alter */ +foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css index ceea4ec..3460cfb 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css @@ -11,4 +11,4 @@ foo {background:url('//cnd.com/A/B/bar/foo.png')} foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ -foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ \ No newline at end of file +foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/in.css b/min_unit_tests/_test_files/css_uriRewriter/in.css index aa41d0a..df80a22 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/in.css +++ b/min_unit_tests/_test_files/css_uriRewriter/in.css @@ -11,4 +11,6 @@ foo {background:url('bar/foo.png')} foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */ -foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ \ No newline at end of file +foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */ +foo {background:url(about:blank);} /* about:blank, should not alter */ +foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ From bb03aa097d4b1536767223851a0fcc3ddac7d0ff Mon Sep 17 00:00:00 2001 From: Joe Cai Date: Thu, 2 Jan 2014 22:32:41 +0800 Subject: [PATCH 2/4] about:blank check with regex --- min/lib/Minify/CSS/UriRewriter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/lib/Minify/CSS/UriRewriter.php b/min/lib/Minify/CSS/UriRewriter.php index e1c67ed..56f3424 100644 --- a/min/lib/Minify/CSS/UriRewriter.php +++ b/min/lib/Minify/CSS/UriRewriter.php @@ -284,7 +284,7 @@ class Minify_CSS_UriRewriter { } // analyze URI if ('/' !== $uri[0] // root-relative - && 0 !== strpos($uri, 'about:blank') //about:blank + && !preg_match('~about\:blank(#.*)?$~', $uri) //about:blank && false === strpos($uri, '//') // protocol (non-data) && 0 !== strpos($uri, 'data:') // data protocol ) { From ea866716e7acf0b296ce36fbf641239faaf388e0 Mon Sep 17 00:00:00 2001 From: Joe Cai Date: Thu, 2 Jan 2014 22:44:27 +0800 Subject: [PATCH 3/4] Fixed the last commit --- min/lib/Minify/CSS/UriRewriter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/lib/Minify/CSS/UriRewriter.php b/min/lib/Minify/CSS/UriRewriter.php index 56f3424..af3bbd4 100644 --- a/min/lib/Minify/CSS/UriRewriter.php +++ b/min/lib/Minify/CSS/UriRewriter.php @@ -284,7 +284,7 @@ class Minify_CSS_UriRewriter { } // analyze URI if ('/' !== $uri[0] // root-relative - && !preg_match('~about\:blank(#.*)?$~', $uri) //about:blank + && !preg_match('~^about\:blank(#.*)?$~', $uri) //about:blank && false === strpos($uri, '//') // protocol (non-data) && 0 !== strpos($uri, 'data:') // data protocol ) { From a2487c7c1af7080b9416ddffdc8284590a73f7b5 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 4 Feb 2014 10:31:00 -0500 Subject: [PATCH 4/4] Simplify identifying file-relative URIs in rewriter --- min/lib/Minify/CSS/UriRewriter.php | 8 ++------ min_unit_tests/_test_files/css_uriRewriter/exp.css | 10 ++++------ .../_test_files/css_uriRewriter/exp_prepend.css | 10 ++++------ .../_test_files/css_uriRewriter/exp_prepend2.css | 8 ++++---- min_unit_tests/_test_files/css_uriRewriter/in.css | 10 ++++------ 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/min/lib/Minify/CSS/UriRewriter.php b/min/lib/Minify/CSS/UriRewriter.php index af3bbd4..50360ce 100644 --- a/min/lib/Minify/CSS/UriRewriter.php +++ b/min/lib/Minify/CSS/UriRewriter.php @@ -282,12 +282,8 @@ class Minify_CSS_UriRewriter { ? $m[1] : substr($m[1], 1, strlen($m[1]) - 2); } - // analyze URI - if ('/' !== $uri[0] // root-relative - && !preg_match('~^about\:blank(#.*)?$~', $uri) //about:blank - && false === strpos($uri, '//') // protocol (non-data) - && 0 !== strpos($uri, 'data:') // data protocol - ) { + // if not root/scheme relative and not starts with scheme + if (!preg_match('~^(/|[a-z]+\:)~', $uri)) { // URI is file-relative: rewrite depending on options if (self::$_prependPath === null) { $uri = self::rewriteRelative($uri, self::$_currentDir, self::$_docRoot, self::$_symlinks); diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp.css b/min_unit_tests/_test_files/css_uriRewriter/exp.css index 8a30a2d..bd6d69e 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp.css @@ -3,14 +3,12 @@ @import '/_test_files/bar/foo.css' print; @import '/foo.css' print; @import '/css/foo.css'; /* abs, should not alter */ -@import 'http://foo.com/css/foo.css'; /* abs, should not alter */ +@import 'http://foo.com/css/foo.css'; /* scheme, should not alter */ @import url(/_test_files/foo.css) tv, projection; @import url("/css/foo.css"); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */ -@import url(data:image/gif;base64,AAAA); /* data, should not alter */ +@import url(foo:bar); /* scheme, should not alter */ foo {background:url('/_test_files/css_uriRewriter/bar/foo.png')} -foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ +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(data:image/gif;base64,AAAA);} /* data, should not alter */ -foo {background:url(about:blank);} /* about:blank, should not alter */ -foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ +foo {background:url(foo:bar);} /* scheme, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css index 251c593..d00cd35 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend.css @@ -3,14 +3,12 @@ @import 'http://cnd.com/A/bar/foo.css' print; @import 'http://cnd.com/foo.css' print; @import '/css/foo.css'; /* abs, should not alter */ -@import 'http://foo.com/css/foo.css'; /* abs, should not alter */ +@import 'http://foo.com/css/foo.css'; /* scheme, should not alter */ @import url(http://cnd.com/A/foo.css) tv, projection; @import url("/css/foo.css"); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */ -@import url(data:image/gif;base64,AAAA); /* data, should not alter */ +@import url(foo:bar); /* scheme, should not alter */ foo {background:url('http://cnd.com/A/B/bar/foo.png')} -foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ +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(data:image/gif;base64,AAAA);} /* data, should not alter */ -foo {background:url(about:blank);} /* about:blank, should not alter */ -foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ +foo {background:url(foo:bar);} /* scheme, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css index 3460cfb..55badf5 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css +++ b/min_unit_tests/_test_files/css_uriRewriter/exp_prepend2.css @@ -3,12 +3,12 @@ @import '//cnd.com/A/bar/foo.css' print; @import '//cnd.com/foo.css' print; @import '/css/foo.css'; /* abs, should not alter */ -@import 'http://foo.com/css/foo.css'; /* abs, should not alter */ +@import 'http://foo.com/css/foo.css'; /* scheme, should not alter */ @import url(//cnd.com/A/foo.css) tv, projection; @import url("/css/foo.css"); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */ -@import url(data:image/gif;base64,AAAA); /* data, should not alter */ +@import url(foo:bar); /* scheme, should not alter */ foo {background:url('//cnd.com/A/B/bar/foo.png')} -foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ +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(data:image/gif;base64,AAAA);} /* data, should not alter */ +foo {background:url(foo:bar);} /* scheme, should not alter */ diff --git a/min_unit_tests/_test_files/css_uriRewriter/in.css b/min_unit_tests/_test_files/css_uriRewriter/in.css index df80a22..3497b87 100644 --- a/min_unit_tests/_test_files/css_uriRewriter/in.css +++ b/min_unit_tests/_test_files/css_uriRewriter/in.css @@ -3,14 +3,12 @@ @import '../bar/foo.css' print; @import '../../foo.css' print; @import '/css/foo.css'; /* abs, should not alter */ -@import 'http://foo.com/css/foo.css'; /* abs, should not alter */ +@import 'http://foo.com/css/foo.css'; /* scheme, should not alter */ @import url(../foo.css) tv, projection; @import url("/css/foo.css"); /* abs, should not alter */ @import url(/css2/foo.css); /* abs, should not alter */ -@import url(data:image/gif;base64,AAAA); /* data, should not alter */ +@import url(foo:bar); /* scheme, should not alter */ foo {background:url('bar/foo.png')} -foo {background:url('http://foo.com/css/foo.css');} /* abs, should not alter */ +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(data:image/gif;base64,AAAA);} /* data, should not alter */ -foo {background:url(about:blank);} /* about:blank, should not alter */ -foo {background:url(about:blank#tab-a);} /* about:blank with a fragment identifier, should not alter */ +foo {background:url(foo:bar);} /* scheme, should not alter */