diff --git a/newIDE/app/src/UI/CorsAwareImage.js b/newIDE/app/src/UI/CorsAwareImage.js index 342136deaac2..a020bc48208a 100644 --- a/newIDE/app/src/UI/CorsAwareImage.js +++ b/newIDE/app/src/UI/CorsAwareImage.js @@ -22,8 +22,27 @@ const addSearchParameterToUrl = ( return url; } - const separator = url.indexOf('?') === -1 ? '?' : '&'; - return url + separator + urlEncodedParameterName + '=' + urlEncodedValue; + const searchParams = url.indexOf('?') === -1 ? '' : url.split('?')[1]; + const urlWithoutSearchParams = searchParams ? url.split('?')[0] : url; + const fileName = urlWithoutSearchParams.split('/').pop(); + const urlWithoutSearchParamsAndFileName = urlWithoutSearchParams.replace( + '/' + fileName, + '' + ); + + const encodedFileName = encodeURIComponent(fileName); + const newSearchParam = urlEncodedParameterName + '=' + urlEncodedValue; + const searchParamsWithNewParam = searchParams + ? searchParams + '&' + newSearchParam + : newSearchParam; + + return ( + urlWithoutSearchParamsAndFileName + + '/' + + encodedFileName + + '?' + + searchParamsWithNewParam + ); }; /**