File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,12 @@ describe('search css url function', () => {
56
56
) ,
57
57
) . toBe ( true )
58
58
} )
59
+
60
+ test ( 'should capture the full url with escaped parentheses' , ( ) => {
61
+ const css = 'background-image: url(public/awkward-name\\)2.png);'
62
+ const match = cssUrlRE . exec ( css )
63
+ expect ( match ?. [ 1 ] . trim ( ) ) . toBe ( 'public/awkward-name\\)2.png' )
64
+ } )
59
65
} )
60
66
61
67
describe ( 'css modules' , ( ) => {
Original file line number Diff line number Diff line change @@ -1896,7 +1896,7 @@ type CssUrlReplacer = (
1896
1896
) => string | false | Promise < string | false >
1897
1897
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
1898
1898
export const cssUrlRE =
1899
- / (?< ! @ i m p o r t \s + ) (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1899
+ / (?< ! @ i m p o r t \s + ) (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | (?: \\ . | [ ^ ' " ) \\ ] ) + ) \) /
1900
1900
export const cssDataUriRE =
1901
1901
/ (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1902
1902
export const importCssRE =
@@ -2049,14 +2049,17 @@ async function doUrlReplace(
2049
2049
if ( skipUrlReplacer ( unquotedUrl ) ) {
2050
2050
return matched
2051
2051
}
2052
+ // Remove escape sequences to get the actual file name before resolving.
2053
+ unquotedUrl = unquotedUrl . replace ( / \\ ( \W ) / g, '$1' )
2052
2054
2053
2055
let newUrl = await replacer ( unquotedUrl , rawUrl )
2054
2056
if ( newUrl === false ) {
2055
2057
return matched
2056
2058
}
2057
2059
2058
- // The new url might need wrapping even if the original did not have it, e.g. if a space was added during replacement
2059
- if ( wrap === '' && newUrl !== encodeURI ( newUrl ) ) {
2060
+ // The new url might need wrapping even if the original did not have it, e.g.
2061
+ // if a space was added during replacement or the URL contains ")"
2062
+ if ( wrap === '' && ( newUrl !== encodeURI ( newUrl ) || newUrl . includes ( ')' ) ) ) {
2060
2063
wrap = '"'
2061
2064
}
2062
2065
// If wrapping in single quotes and newUrl also contains single quotes, switch to double quotes.
You can’t perform that action at this time.
0 commit comments