@@ -29,9 +29,35 @@ module.exports = function (css) {
2929 var currentDir = baseUrl + location . pathname . replace ( / \/ [ ^ \/ ] * $ / , "/" ) ;
3030
3131 // convert each url(...)
32- var fixedCss = css . replace ( / u r l * \( * ( .+ ?) * \) / g, function ( fullMatch , origUrl ) {
32+ /*
33+ This regular expression is just a way to recursively match brackets within
34+ a string.
35+
36+ /url\s*\( = Match on the word "url" with any whitespace after it and then a parens
37+ ( = Start a capturing group
38+ (?: = Start a non-capturing group
39+ [^)(] = Match anything that isn't a parentheses
40+ | = OR
41+ \( = Match a start parentheses
42+ (?: = Start another non-capturing groups
43+ [^)(]+ = Match anything that isn't a parentheses
44+ | = OR
45+ \( = Match a start parentheses
46+ [^)(]* = Match anything that isn't a parentheses
47+ \) = Match a end parentheses
48+ ) = End Group
49+ *\) = Match anything and then a close parens
50+ ) = Close non-capturing group
51+ * = Match anything
52+ ) = Close capturing group
53+ \) = Match a close parens
54+
55+ /gi = Get all matches, not the first. Be case insensitive.
56+ */
57+ var fixedCss = css . replace ( / u r l \s * \( ( (?: [ ^ ) ( ] | \( (?: [ ^ ) ( ] + | \( [ ^ ) ( ] * \) ) * \) ) * ) \) / gi, function ( fullMatch , origUrl ) {
3358 // strip quotes (if they exist)
3459 var unquotedOrigUrl = origUrl
60+ . trim ( )
3561 . replace ( / ^ " ( .* ) " $ / , function ( o , $1 ) { return $1 ; } )
3662 . replace ( / ^ ' ( .* ) ' $ / , function ( o , $1 ) { return $1 ; } ) ;
3763
0 commit comments