@@ -534,8 +534,11 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
534
534
const processedEncodedUrl = await processSrcSet (
535
535
attr . value ,
536
536
async ( { url } ) => {
537
- const decodedUrl = decodeURI ( url )
538
- if ( ! isExcludedUrl ( decodedUrl ) ) {
537
+ const decodedUrl = decodeURIIfPossible ( url )
538
+ if (
539
+ decodedUrl !== undefined &&
540
+ ! isExcludedUrl ( decodedUrl )
541
+ ) {
539
542
const result = await processAssetUrl ( url )
540
543
return result !== decodedUrl
541
544
? encodeURIPath ( result )
@@ -550,8 +553,10 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
550
553
} ) ( ) ,
551
554
)
552
555
} else if ( attr . type === 'src' ) {
553
- const url = decodeURI ( attr . value )
554
- if ( checkPublicFile ( url , config ) ) {
556
+ const url = decodeURIIfPossible ( attr . value )
557
+ if ( url === undefined ) {
558
+ // ignore it
559
+ } else if ( checkPublicFile ( url , config ) ) {
555
560
overwriteAttrValue (
556
561
s ,
557
562
attr . location ,
@@ -1580,3 +1585,12 @@ function serializeAttrs(attrs: HtmlTagDescriptor['attrs']): string {
1580
1585
function incrementIndent ( indent : string = '' ) {
1581
1586
return `${ indent } ${ indent [ 0 ] === '\t' ? '\t' : ' ' } `
1582
1587
}
1588
+
1589
+ function decodeURIIfPossible ( input : string ) : string | undefined {
1590
+ try {
1591
+ return decodeURI ( input )
1592
+ } catch {
1593
+ // url is malformed, probably a interpolate syntax of template engines
1594
+ return
1595
+ }
1596
+ }
0 commit comments