File tree 5 files changed +41
-4
lines changed
5 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -207,9 +207,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
207
207
}
208
208
209
209
return {
210
- code : `export default ${ JSON . stringify (
211
- url . startsWith ( 'data:' ) ? url : encodeURIPath ( url ) ,
212
- ) } `,
210
+ code : `export default ${ JSON . stringify ( encodeURIPath ( url ) ) } ` ,
213
211
// Force rollup to keep this module from being shared between other entry points if it's an entrypoint.
214
212
// If the resulting chunk is empty, it will be removed in generateBundle.
215
213
moduleSideEffects :
Original file line number Diff line number Diff line change @@ -1421,6 +1421,7 @@ export function displayTime(time: number): string {
1421
1421
* Encodes the URI path portion (ignores part after ? or #)
1422
1422
*/
1423
1423
export function encodeURIPath ( uri : string ) : string {
1424
+ if ( uri . startsWith ( 'data:' ) ) return uri
1424
1425
const filePath = cleanUrl ( uri )
1425
1426
const postfix = filePath !== uri ? uri . slice ( filePath . length ) : ''
1426
1427
return encodeURI ( filePath ) + postfix
@@ -1431,6 +1432,7 @@ export function encodeURIPath(uri: string): string {
1431
1432
* that can handle un-encoded URIs, where `%` is the only ambiguous character.
1432
1433
*/
1433
1434
export function partialEncodeURIPath ( uri : string ) : string {
1435
+ if ( uri . startsWith ( 'data:' ) ) return uri
1434
1436
const filePath = cleanUrl ( uri )
1435
1437
const postfix = filePath !== uri ? uri . slice ( filePath . length ) : ''
1436
1438
return filePath . replaceAll ( '%' , '%25' ) + postfix
Original file line number Diff line number Diff line change @@ -282,6 +282,26 @@ describe('css url() references', () => {
282
282
} )
283
283
284
284
describe ( 'image' , ( ) => {
285
+ test ( 'src' , async ( ) => {
286
+ const img = await page . $ ( '.img-src' )
287
+ const src = await img . getAttribute ( 'src' )
288
+ expect ( src ) . toMatch (
289
+ isBuild
290
+ ? / \/ f o o \/ b a r \/ a s s e t s \/ h t m l - o n l y - a s s e t - [ - \w ] { 8 } \. j p g /
291
+ : / \/ f o o \/ b a r \/ n e s t e d \/ h t m l - o n l y - a s s e t .j p g / ,
292
+ )
293
+ } )
294
+
295
+ test ( 'src inline' , async ( ) => {
296
+ const img = await page . $ ( '.img-src-inline' )
297
+ const src = await img . getAttribute ( 'src' )
298
+ expect ( src ) . toMatch (
299
+ isBuild
300
+ ? / ^ d a t a : i m a g e \/ s v g \+ x m l , % 3 c s v g /
301
+ : / \/ f o o \/ b a r \/ n e s t e d \/ i n l i n e d .s v g / ,
302
+ )
303
+ } )
304
+
285
305
test ( 'srcset' , async ( ) => {
286
306
const img = await page . $ ( '.img-src-set' )
287
307
const srcset = await img . getAttribute ( 'srcset' )
Original file line number Diff line number Diff line change @@ -175,7 +175,12 @@ <h2>Image Src Set</h2>
175
175
176
176
< h2 > HTML only asset</ h2 >
177
177
< div >
178
- < img src ="./nested/html-only-asset.jpg " alt ="" />
178
+ < img class ="img-src " src ="./nested/html-only-asset.jpg " alt ="" />
179
+ </ div >
180
+
181
+ < h2 > HTML inline asset</ h2 >
182
+ < div >
183
+ < img class ="img-src-inline " src ="./nested/inlined.svg " alt ="" />
179
184
</ div >
180
185
181
186
< h2 > SVG Fragments</ h2 >
You can’t perform that action at this time.
0 commit comments