Skip to content

Commit

Permalink
Merge branch 'hotfix/data-regex-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Mathias committed Mar 5, 2013
2 parents 0599f4a + 8030588 commit 34101bf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
@@ -1,5 +1,8 @@
# CHANGE LOG

1.1.7
- Further updated regex around "data:" values in url in CSS. Improved documentation of these regular expressions.

## 1.1.6
- Updated to allow data: values in url in stylesheet.

Expand Down
55 changes: 48 additions & 7 deletions cf-asset-optimizer.php
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://crowdfavorite.com
Description: Used to serve optimized and concatenated JS and CSS files enqueued on a page.
Author: Crowd Favorite
Version: 1.1.6
Version: 1.1.7
Author URI: http://crowdfavorite.com
*/

Expand Down Expand Up @@ -674,15 +674,56 @@ public static function buildConcatenatedStyleFile() {

// Update paths that are based on web root.
if (count($parts) > 1) {
$src = preg_replace('#url\s*\(\s*(["\']?)\s*(/[^[:space:]|data:].+?)\s*\1\s*\)#x',
'url('.$parts[1].'$2)', $src
);
$regex = '~
url\s*\( # url( with optional internal whitespace
\s* # optional whitespace
( # begin group 1
["\']? # an optional single or double quote
) # end option group 1
\s* # optional whitespace
( # begin option group 2
/ # url starts with / for web root url
[^[:space:]] # one single non-space character
.+? # one or more (non-greedy) any character
) # end option group 2
\s* # optional whitespace
\1 # match opening delimiter
\s* # optional whitespace
\) # closing )
~x';
$src = preg_replace($regex,'url('.$parts[1].'$2)', $src);
}
// Update paths based on script location
if (count($parts) > 2) {
$src = preg_replace('#url\s*\(\s*(["\']?)\s*(?!(?://|https?://))(/?[^[:space:]|data:].+?)\s*\1\s*\)#x',
'url('.$parts[1].$parts[2].'$2)', $src
);
$regex = '~
url\s*\( # url( with optional internal whitespace
\s* # optional whitespace
( # begin group 1 (optional delimiter)
["\']? # an optional single or double quote
) # end group 1
\s* # optional whitespace
(?! # negative lookahead assertion: skip if...
(?: # noncapturing group (not needed with lookaheads)
// # url starts with //
| # or
https?:// # url starts with http:// or https://
| # or
data: # url starts with data:
) # end noncapturing group
) # end negative lookahead
( # begin group 2 (relative URL)
/? # optional root /
[^[:space:]] # one single nonspace character
.+? # one or more (non-greedy) any character
) # end group 2
\s* # optional whitespace
\1 # match opening delimiter
\s* # optional whitespace
\) # closing )
~x';
$src = preg_replace($regex, 'url('.$parts[1].$parts[2].'$2)', $src);
}

$style_file_src .= $src . "\n";
Expand Down

0 comments on commit 34101bf

Please sign in to comment.