@@ -562,6 +562,7 @@ export class CoreFileHelperProvider {
562562 if ( filename . indexOf ( '?' ) != - 1 ) {
563563 filename = filename . substring ( 0 , filename . indexOf ( '?' ) ) ;
564564 }
565+ filename = CoreUrl . decodeURIComponent ( filename ) ;
565566
566567 if ( pluginfileMap [ filename ] ) {
567568 replaceMap [ url ] = pluginfileMap [ filename ] ;
@@ -611,23 +612,24 @@ export class CoreFileHelperProvider {
611612 const draftfileUrlRegexPrefix = CoreText . escapeForRegex ( draftfileUrl ) + '/[^/]+/[^/]+/[^/]+/[^/]+/' ;
612613
613614 files . forEach ( ( file ) => {
614- if ( ! file . filename ) {
615- return ;
615+ // Get the file name from the URL instead of using file.filename because the URL can have encoded characters.
616+ // encodeURIComponent doesn't encode parenthesis, so it's better to rely on the name from the URL.
617+ const url = CoreFileHelper . getFileUrl ( file ) ;
618+ let filename = url . substring ( url . lastIndexOf ( '/' ) + 1 ) ;
619+ if ( filename . indexOf ( '?' ) != - 1 ) {
620+ filename = filename . substring ( 0 , filename . indexOf ( '?' ) ) ;
616621 }
617622
618623 // Search the draftfile URL in the original text.
619624 const matches = originalText . match (
620- new RegExp ( draftfileUrlRegexPrefix + CoreText . escapeForRegex ( file . filename ) + '[^\'" ]*' , 'i' ) ,
625+ new RegExp ( draftfileUrlRegexPrefix + CoreText . escapeForRegex ( filename ) + '[^\'" ]*' , 'i' ) ,
621626 ) ;
622627
623628 if ( ! matches || ! matches [ 0 ] ) {
624629 return ; // Original URL not found, skip.
625630 }
626631
627- treatedText = treatedText . replace (
628- new RegExp ( CoreText . escapeForRegex ( CoreFileHelper . getFileUrl ( file ) ) , 'g' ) ,
629- matches [ 0 ] ,
630- ) ;
632+ treatedText = treatedText . replace ( new RegExp ( CoreText . escapeForRegex ( url ) , 'g' ) , matches [ 0 ] ) ;
631633 } ) ;
632634
633635 return treatedText ;
0 commit comments