File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,6 +145,17 @@ composes: bar from '@/css/bar.module.css';
145145 } )
146146} )
147147
148+ describe ( 'url()' , ( ) => {
149+ test ( 'keeps a % that is not an escape sequence' , async ( ) => {
150+ const { transform } = await createCssPluginTransform ( { configFile : false } )
151+ const result = await transform (
152+ `.foo { background: url(./100%.png) }` ,
153+ '/foo.css' ,
154+ )
155+ expect ( result . code ) . toContain ( '100%.png' )
156+ } )
157+ } )
158+
148159describe ( 'hoist @ rules' , ( ) => {
149160 test ( 'hoist @import' , async ( ) => {
150161 const css = `.foo{color:red;}@import "bla";`
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import {
7373 asyncReplace ,
7474 combineSourcemaps ,
7575 createSerialPromiseQueue ,
76+ decodeURIIfPossible ,
7677 emptyCssComments ,
7778 encodeURIPath ,
7879 escapeRegex ,
@@ -394,7 +395,9 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
394395 idResolver ( environment , url , importer )
395396
396397 const urlResolver : CssUrlResolver = async ( url , importer ) => {
397- const decodedUrl = decodeURI ( url )
398+ // a `%` that doesn't start an escape sequence (e.g. `url(100%.png)`)
399+ // is kept as is, like browsers do
400+ const decodedUrl = decodeURIIfPossible ( url ) ?? url
398401 if ( checkPublicFile ( decodedUrl , config ) ) {
399402 if ( encodePublicUrlsInCSS ( config ) ) {
400403 return [ publicFileToBuiltUrl ( decodedUrl , config ) , undefined ]
You can’t perform that action at this time.
0 commit comments