* non-existent files.
*
* @param string $source CSS stylesheet source to process
- * @param string $path File path where the source wa
+ * @param string $path File path where the source was read from
* @return array List of local file references
*/
public static function getAllLocalFileReferences( $source, $path ) {
+ $stripped = preg_replace( '/' . self::COMMENT_REGEX . '/s', '', $source );
$path = rtrim( $path, '/' ) . '/';
$files = array();
$rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
- if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, $rFlags ) ) {
+ if ( preg_match_all( '/' . self::URL_REGEX . '/', $stripped, $matches, $rFlags ) ) {
foreach ( $matches as $match ) {
$url = $match['file'][0];
--- /dev/null
+/* url expressions in comments should be ignored */
+
+.selector { /*@noflip*/ background-image: /*@embed*/ url(not-commented.gif); }
+
+/*
+.selector { background-image: url(commented-out.gif); }
+*/
}
}
+ /**
+ * CSSMin::getAllLocalFileReferences should ignore url(...) expressions
+ * that have been commented out.
+ */
+ public function testCommentedLocalFileReferences() {
+ $basepath = __DIR__ . '/../data/css/';
+ $css = file_get_contents( $basepath . 'comments.css' );
+ $files = CSSMin::getAllLocalFileReferences( $css, $basepath );
+ $expected = array( $basepath . 'not-commented.gif' );
+ $this->assertArrayEquals(
+ $expected,
+ $files,
+ 'Url(...) expression in comment should be omitted.'
+ );
+ }
+
/**
* Get all registered modules from ResouceLoader.
* @return array