CSSMin: Fix breaking of quoted urls with outer spacing
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 13 Mar 2018 00:20:20 +0000 (17:20 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Apr 2018 16:20:22 +0000 (17:20 +0100)
Bug:  T189375
Change-Id: I9226ec9bd21d7dedc964fbc1dc1f0914abe458d5
(cherry picked from commit 5333d63cbc3d97689c3eb0ab520abc4b264dc0dd)

RELEASE-NOTES-1.31
includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php

index 4af03ee..2758d4c 100644 (file)
@@ -130,7 +130,8 @@ production.
 * mediawiki/at-ease was replaced with wikimedia/at-ease.
 
 === Bug fixes in 1.31 ===
-* (T90902) Non-breaking space in header ID breaks anchor
+* (T90902) Non-breaking space in header ID breaks anchor.
+* (T189375) CSSMin now allows unquoted urls in `url()` syntax to start with a space.
 
 === Action API changes in 1.31 ===
 * (T185058) The 'name' value to tgprop for action=query&list=tags has been
index b538d3b..1ee7a3b 100644 (file)
@@ -421,7 +421,7 @@ class CSSMin {
                        //   is only supported in PHP 5.6. Use a getter method for now.
                        $urlRegex = '(' .
                                // Unquoted url
-                               'url\(\s*(?P<file0>[^\'"][^\?\)]+?)(?P<query0>\?[^\)]*?|)\s*\)' .
+                               'url\(\s*(?P<file0>[^\s\'"][^\?\)]+?)(?P<query0>\?[^\)]*?|)\s*\)' .
                                // Single quoted url
                                '|url\(\s*\'(?P<file1>[^\?\']+?)(?P<query1>\?[^\']*?|)\'\s*\)' .
                                // Double quoted url
index 02b3549..46bf2c6 100644 (file)
@@ -515,7 +515,7 @@ class CSSMinTest extends MediaWikiTestCase {
                                'foo { background: url(//localhost/styles.css?quoted=single) }',
                        ],
                        [
-                               'Background URL (containing parentheses; T60473)',
+                               'Background URL (double quoted, containing parentheses; T60473)',
                                'foo { background: url("//localhost/styles.css?query=(parens)") }',
                                'foo { background: url("//localhost/styles.css?query=(parens)") }',
                        ],
@@ -529,6 +529,11 @@ class CSSMinTest extends MediaWikiTestCase {
                                'foo { background: url(\'//localhost/styles.css?quote="\') }',
                                'foo { background: url("//localhost/styles.css?quote=\"") }',
                        ],
+                       [
+                               'Background URL (double quoted with outer spacing)',
+                               'foo { background: url( "http://localhost/styles.css?quoted=double" ) }',
+                               'foo { background: url(http://localhost/styles.css?quoted=double) }',
+                       ],
                        [
                                'Simple case with comments before url',
                                'foo { prop: /* some {funny;} comment */ url(bar.png); }',