Skip to content

Commit

Permalink
Handle encoding filename when displaying it in the IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau committed Jan 18, 2024
1 parent a1a4029 commit a19d477
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions newIDE/app/src/UI/CorsAwareImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};

/**
Expand Down

0 comments on commit a19d477

Please sign in to comment.