mirror of
https://github.com/mrclay/minify.git
synced 2025-02-23 08:25:12 +01:00
CSS.php & CSS/UriRewriter.php : support for data URIs (Issue 80)
This commit is contained in:
parent
039a25fc7c
commit
323ec7eb53
@ -278,7 +278,9 @@ class Minify_CSS {
|
||||
: substr($m[1], 1, strlen($m[1]) - 2);
|
||||
}
|
||||
if ('/' !== $url[0]) {
|
||||
if (strpos($url, '//') > 0) {
|
||||
if (strpos($url, '//') > 0
|
||||
|| 0 === strpos($url, 'data:')
|
||||
) {
|
||||
// probably starts with protocol, do not alter
|
||||
} else {
|
||||
// relative URI, rewrite!
|
||||
|
@ -14,6 +14,13 @@
|
||||
*/
|
||||
class Minify_CSS_UriRewriter {
|
||||
|
||||
/**
|
||||
* Defines which class to call as part of callbacks, change this
|
||||
* if you extend Minify_CSS_UriRewriter
|
||||
* @var string
|
||||
*/
|
||||
protected static $className = 'Minify_CSS_UriRewriter';
|
||||
|
||||
/**
|
||||
* Rewrite file relative URIs as root relative in CSS files
|
||||
*
|
||||
@ -45,9 +52,9 @@ class Minify_CSS_UriRewriter {
|
||||
|
||||
// rewrite
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array('Minify_CSS_UriRewriter', '_uriCB'), $css);
|
||||
,array(self::$className, '_uriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
,array('Minify_CSS_UriRewriter', '_uriCB'), $css);
|
||||
,array(self::$className, '_uriCB'), $css);
|
||||
|
||||
return $css;
|
||||
}
|
||||
@ -79,7 +86,9 @@ class Minify_CSS_UriRewriter {
|
||||
: substr($m[1], 1, strlen($m[1]) - 2);
|
||||
}
|
||||
if ('/' !== $uri[0]) {
|
||||
if (strpos($uri, '//') > 0) {
|
||||
if (strpos($uri, '//') > 0
|
||||
|| 0 === strpos($uri, 'data:')
|
||||
) {
|
||||
// probably starts with protocol, do not alter
|
||||
} else {
|
||||
// it's a file relative URI!
|
||||
|
@ -5,6 +5,8 @@
|
||||
@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 */
|
||||
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("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */
|
2
min_unit_tests/_test_files/css/paths.min.css
vendored
2
min_unit_tests/_test_files/css/paths.min.css
vendored
@ -1 +1 @@
|
||||
@import "../foo.css";@import '../bar/foo.css' print;@import '/css/foo.css';@import 'http://foo.com/css/foo.css';@import url(../../foo.css) tv, projection;@import url("/css/foo.css");@import url(/css2/foo.css);foo{background:url('../bar/foo.png')}foo{background:url('http://foo.com/css/foo.css')}foo{background:url("//foo.com/css/foo.css")}
|
||||
@import "../foo.css";@import '../bar/foo.css' print;@import '/css/foo.css';@import 'http://foo.com/css/foo.css';@import url(../../foo.css) tv, projection;@import url("/css/foo.css");@import url(/css2/foo.css);@import url(data:image/gif;base64,AAAA);foo{background:url('../bar/foo.png')}foo{background:url('http://foo.com/css/foo.css')}foo{background:url("//foo.com/css/foo.css")}foo{background:url(data:image/gif;base64,AAAA)}
|
@ -7,6 +7,8 @@
|
||||
@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 */
|
||||
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("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */
|
@ -7,6 +7,8 @@
|
||||
@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 */
|
||||
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("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(data:image/gif;base64,AAAA);} /* data, should not alter */
|
@ -25,12 +25,14 @@
|
||||
/* 22 */ fixHrefs();
|
||||
/* 23 */ };
|
||||
/* 24 */ })();
|
||||
|
||||
;
|
||||
/* lines_bugs.js */
|
||||
|
||||
/* 1 */ var triggerBug = {_default: "*/*"};
|
||||
/* 2 */ var essentialFunctionality = true;
|
||||
/* 3 */
|
||||
|
||||
;
|
||||
/* QueryString.js */
|
||||
|
||||
@ -211,6 +213,7 @@
|
||||
/* 166 */
|
||||
/* 167 */ return construct_;
|
||||
/* 168 */ }(); // define and execute
|
||||
|
||||
;
|
||||
/* before.js */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user