$url = $match['file'][0];
// Skip fully-qualified and protocol-relative URLs and data URIs
- // Also skips the rare `behavior` property specifying application's default behavior
if (
substr( $url, 0, 2 ) === '//' ||
- parse_url( $url, PHP_URL_SCHEME ) ||
- substr( $url, 0, 9 ) === '#default#'
+ parse_url( $url, PHP_URL_SCHEME )
) {
break;
}
+ // Strip trailing anchors - T115436
+ $anchor = strpos( $url, '#' );
+ if ( $anchor !== false ) {
+ $url = substr( $url, 0, $anchor );
+
+ // '#some-anchors' is not a file
+ if ( $url === '' ) {
+ break;
+ }
+ }
+
$files[] = $path . $url;
}
}
// Pass thru fully-qualified and protocol-relative URLs and data URIs, as well as local URLs if
// we can't expand them.
- // Also skips the rare `behavior` property specifying application's default behavior
+ // Also skips anchors or the rare `behavior` property specifying application's default behavior
if (
self::isRemoteUrl( $url ) ||
self::isLocalUrl( $url ) ||
- substr( $url, 0, 9 ) === '#default#'
+ substr( $url, 0, 1 ) === '#'
) {
return $url;
}
] );
}
+ /**
+ * @dataProvider providesReferencedFiles
+ * @covers CSSMin::getLocalFileReferences
+ */
+ public function testGetLocalFileReferences( $input, $expected ) {
+ $output = CSSMin::getLocalFileReferences( $input, '/' );
+ $this->assertEquals(
+ $expected,
+ $output,
+ 'getLocalFileReferences() must find the local file properly'
+ );
+ }
+
+ public static function providesReferencedFiles() {
+ // input, array of expected local file names
+ return [
+ [ 'url("//example.org")', [] ],
+ [ 'url("https://example.org")', [] ],
+ [ 'url("#default#")', [] ],
+ [ 'url("WikiFont-Glyphs.svg#wikiglyph")', [ '/WikiFont-Glyphs.svg' ] ],
+ [ 'url("#some-anchor")', [] ],
+ ];
+ }
+
/**
* @dataProvider provideSerializeStringValue
* @covers CSSMin::serializeStringValue
[ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
'foo { behavior: url("#default#bar"); }',
],
+ [
+ 'Keeps anchors',
+ [ 'url(#other)', false, '/', false ],
+ 'url("#other")'
+ ],
+ [
+ 'Keeps anchors after a path',
+ [ 'url(images/file.svg#id)', false, '/', false ],
+ 'url("/images/file.svg#id")'
+ ],
];
}