// 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>[^\'"][^\?\)]+?)(?P<query0>\?[^\)]*?|)\s*\)' .
// Single quoted url
- '|url\(\s*\'(?P<file1>[^\?\']*?)(?P<query1>\?[^\']*?|)\'\s*\)' .
+ '|url\(\s*\'(?P<file1>[^\?\']+?)(?P<query1>\?[^\']*?|)\'\s*\)' .
// Double quoted url
- '|url\(\s*"(?P<file2>[^\?"]*?)(?P<query2>\?[^"]*?|)"\s*\)' .
+ '|url\(\s*"(?P<file2>[^\?"]+?)(?P<query2>\?[^"]*?|)"\s*\)' .
')';
}
return $urlRegex;
$match['file'] = $match['file1'];
$match['query'] = $match['query1'];
} else {
+ if ( !isset( $match['file2'] ) || $match['file2'][1] === -1 ) {
+ throw new Exception( 'URL must be non-empty' );
+ }
$match['file'] = $match['file2'];
$match['query'] = $match['query2'];
}
$match['file'] = $match['file1'];
$match['query'] = $match['query1'];
} else {
+ if ( !isset( $match['file2'] ) || $match['file2'] === '' ) {
+ throw new Exception( 'URL must be non-empty' );
+ }
$match['file'] = $match['file2'];
$match['query'] = $match['query2'];
}
];
}
+ /**
+ * Cases with empty url() for CSSMin::remap.
+ *
+ * Regression test for T191237.
+ *
+ * @dataProvider provideRemapEmptyUrl
+ * @covers CSSMin
+ */
+ public function testRemapEmptyUrl( $params, $expected ) {
+ $remapped = call_user_func_array( 'CSSMin::remap', $params );
+ $this->assertEquals( $expected, $remapped, 'Ignore empty url' );
+ }
+
+ public static function provideRemapEmptyUrl() {
+ return [
+ 'Empty' => [
+ [ "background-image: url();", false, '/example', false ],
+ "background-image: url();",
+ ],
+ 'Single quote' => [
+ [ "background-image: url('');", false, '/example', false ],
+ "background-image: url('');",
+ ],
+ 'Double quote' => [
+ [ 'background-image: url("");', false, '/example', false ],
+ 'background-image: url("");',
+ ],
+ ];
+ }
+
/**
* This tests the basic functionality of CSSMin::remap.
*