File tree Expand file tree Collapse file tree 5 files changed +41
-4
lines changed Expand file tree Collapse file tree 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 {
207207 }
208208
209209 return {
210- code : `export default ${ JSON . stringify (
211- url . startsWith ( 'data:' ) ? url : encodeURIPath ( url ) ,
212- ) } `,
210+ code : `export default ${ JSON . stringify ( encodeURIPath ( url ) ) } ` ,
213211 // Force rollup to keep this module from being shared between other entry points if it's an entrypoint.
214212 // If the resulting chunk is empty, it will be removed in generateBundle.
215213 moduleSideEffects :
Original file line number Diff line number Diff line change @@ -1421,6 +1421,7 @@ export function displayTime(time: number): string {
14211421 * Encodes the URI path portion (ignores part after ? or #)
14221422 */
14231423export function encodeURIPath ( uri : string ) : string {
1424+ if ( uri . startsWith ( 'data:' ) ) return uri
14241425 const filePath = cleanUrl ( uri )
14251426 const postfix = filePath !== uri ? uri . slice ( filePath . length ) : ''
14261427 return encodeURI ( filePath ) + postfix
@@ -1431,6 +1432,7 @@ export function encodeURIPath(uri: string): string {
14311432 * that can handle un-encoded URIs, where `%` is the only ambiguous character.
14321433 */
14331434export function partialEncodeURIPath ( uri : string ) : string {
1435+ if ( uri . startsWith ( 'data:' ) ) return uri
14341436 const filePath = cleanUrl ( uri )
14351437 const postfix = filePath !== uri ? uri . slice ( filePath . length ) : ''
14361438 return filePath . replaceAll ( '%' , '%25' ) + postfix
Original file line number Diff line number Diff line change @@ -282,6 +282,26 @@ describe('css url() references', () => {
282282} )
283283
284284describe ( '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+
285305 test ( 'srcset' , async ( ) => {
286306 const img = await page . $ ( '.img-src-set' )
287307 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>
175175
176176< h2 > HTML only asset</ h2 >
177177< 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 ="" />
179184</ div >
180185
181186< h2 > SVG Fragments</ h2 >
You can’t perform that action at this time.
0 commit comments