fix: decode URL-encoded characters #3565
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the URL decoding issue with base64 encoded contract codes.
For example,
bWFwcGluZyhhZGRyZXNzID0+IHVpbnQyNTYpIHB1YmxpYyBmb287
is base64 encoded value ofmapping(address => uint256) public foo;
.+
is URL encoded to%2B
causing the following error in the Remix IDE:The
decodeURIComponent
function is used to decode any URL-encoded characters in the params.code string before passing it to the atob function. This is necessary becauseatob
expects a string that has already been encoded in base64 format and does not handle URL-encoded characters. By applyingdecodeURIComponent
first, you ensure that theatob
function will be able to properly decode the base64-encoded string.NOTE:
The set of characters used in Base64 encoding includes the 26 uppercase letters of the alphabet (A-Z), the 26 lowercase letters (a-z), the 10 digits (0-9), and two additional characters: the plus sign (+) and the forward slash (/). Additionally, the equals sign (=) is used as a padding character to make the length of the output a multiple of 4.