aboutsummaryrefslogtreecommitdiffstats
path: root/includes/libs/CSSMin.php
diff options
context:
space:
mode:
authorBartosz Dziewoński <matma.rex@gmail.com>2013-12-11 22:00:29 +0100
committerBartosz Dziewoński <matma.rex@gmail.com>2013-12-11 22:22:59 +0100
commit2c866d8e731f8def157658ebc79dc3bbd7955f1d (patch)
tree49917efde4d47cfcd29f99d678800c9f1363293c /includes/libs/CSSMin.php
parente36dcfa4c6e821bce7ecdcec3000ebf308e587f3 (diff)
downloadmediawikicore-2c866d8e731f8def157658ebc79dc3bbd7955f1d.tar.gz
mediawikicore-2c866d8e731f8def157658ebc79dc3bbd7955f1d.zip
CSSMin: Correctly format 'url()' values with parentheses etc.
Introduce new static function, CSSMin::buildUrlValue. Actually using such values in CSS does not work well because the URL_REGEX is nowhere near good enough. :( Change-Id: I04a7078dd0087bcb461fa5e5168c870d37c255f4
Diffstat (limited to 'includes/libs/CSSMin.php')
-rw-r--r--includes/libs/CSSMin.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php
index fd5bca45aaaa..3c844729c30b 100644
--- a/includes/libs/CSSMin.php
+++ b/includes/libs/CSSMin.php
@@ -141,6 +141,24 @@ class CSSMin {
}
/**
+ * Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters)
+ * and escaping quotes as necessary.
+ *
+ * @param string $url URL to process
+ * @return string 'url()' value, usually just `"url($url)"`, quoted/escaped if necessary
+ */
+ public static function buildUrlValue( $url ) {
+ // The list below has been crafted to match URLs such as:
+ // scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s
+ // data:image/png;base64,R0lGODlh/+==
+ if ( preg_match( '!^[\w\d:@/~.%+;,?&=-]+$!', $url ) ) {
+ return "url($url)";
+ } else {
+ return 'url("' . strtr( $url, array( '\\' => '\\\\', '"' => '\\"' ) ) . '")';
+ }
+ }
+
+ /**
* Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values
* preceded by an / * @embed * / comment.
*
@@ -182,14 +200,14 @@ class CSSMin {
$ruleWithRemapped = preg_replace_callback( $pattern, function ( $match ) use ( $local, $remote ) {
$remapped = CSSMin::remapOne( $match['file'], $match['query'], $local, $remote, false );
- return "url({$remapped})";
+ return CSSMin::buildUrlValue( $remapped );
}, $rule );
if ( $embedData ) {
$ruleWithEmbedded = preg_replace_callback( $pattern, function ( $match ) use ( $embedAll, $local, $remote ) {
$embed = $embedAll || $match['embed'];
$embedded = CSSMin::remapOne( $match['file'], $match['query'], $local, $remote, $embed );
- return "url({$embedded})";
+ return CSSMin::buildUrlValue( $embedded );
}, $rule );
}