Index: trunk/phase3/includes/libs/CSSMin.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | * result in a 1/3 increase in size. |
36 | 36 | */ |
37 | 37 | const EMBED_SIZE_LIMIT = 24576; |
| 38 | + const URL_REGEX = 'url\([\'"]?(?<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)'; |
38 | 39 | |
39 | 40 | /* Protected Static Members */ |
40 | 41 | |
— | — | @@ -59,9 +60,8 @@ |
60 | 61 | * @return array List of local file references |
61 | 62 | */ |
62 | 63 | public static function getLocalFileReferences( $source, $path = null ) { |
63 | | - $pattern = '/url\([\'"]?(?<file>[^\?\)\:]*)\??[^\)]*[\'"]?\)/'; |
64 | 64 | $files = array(); |
65 | | - if ( preg_match_all( $pattern, $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ) { |
| 65 | + if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ) { |
66 | 66 | foreach ( $matches as $match ) { |
67 | 67 | $file = ( isset( $path ) ? rtrim( $path, '/' ) . '/' : '' ) . "{$match['file'][0]}"; |
68 | 68 | |
— | — | @@ -82,13 +82,13 @@ |
83 | 83 | * @return string Remapped CSS data |
84 | 84 | */ |
85 | 85 | public static function remap( $source, $path, $embed = true ) { |
86 | | - $pattern = '/((?<embed>\s*\/\*\s*\@embed\s*\*\/)(?<rule>[^\;\}]*))?url\([\'"]?(?<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)(?<extra>[^;]*)[\;]?/'; |
| 86 | + $pattern = '/((?<embed>\s*\/\*\s*\@embed\s*\*\/)(?<pre>[^\;\}]*))?' . self::URL_REGEX . '(?<post>[^;]*)[\;]?/'; |
87 | 87 | $offset = 0; |
88 | 88 | while ( preg_match( $pattern, $source, $match, PREG_OFFSET_CAPTURE, $offset ) ) { |
89 | 89 | // Shortcuts |
90 | 90 | $embed = $match['embed'][0]; |
91 | | - $rule = $match['rule'][0]; |
92 | | - $extra = $match['extra'][0]; |
| 91 | + $pre = $match['pre'][0]; |
| 92 | + $post = $match['post'][0]; |
93 | 93 | $file = "{$path}/{$match['file'][0]}"; |
94 | 94 | // Only proceed if we can access the file |
95 | 95 | if ( file_exists( $file ) ) { |
— | — | @@ -117,10 +117,10 @@ |
118 | 118 | // Build 2 CSS properties; one which uses a base64 encoded data URI in place of the @embed |
119 | 119 | // comment to try and retain line-number integrity , and the other with a remapped an versioned |
120 | 120 | // URL and an Internet Explorer hack making it ignored in all browsers that support data URIs |
121 | | - $replacement = "{$rule}url(data:{$type};base64,{$data}){$extra};{$rule}url({$url}){$extra}!ie;"; |
| 121 | + $replacement = "{$pre}url(data:{$type};base64,{$data}){$post};{$pre}url({$url}){$post}!ie;"; |
122 | 122 | } else { |
123 | | - // Build a CSS property with a remapped and versioned URL |
124 | | - $replacement = "{$embed}{$rule}url({$url}){$extra};"; |
| 123 | + // Build a CSS property with a remapped and versioned URL, preserving comment for debug mode |
| 124 | + $replacement = "{$embed}{$pre}url({$url}){$post};"; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Perform replacement on the source |