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)
committerThiemo Kreuz (WMDE) <thiemo.kreuz@wikimedia.de>
Wed, 18 Apr 2018 18:24:07 +0000 (18:24 +0000)
Bug:  T189375
Change-Id: I9226ec9bd21d7dedc964fbc1dc1f0914abe458d5

includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php

index 73825e8..a6014b1 100644 (file)
@@ -420,7 +420,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); }',