fix: stop double encoding query params #459
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.
While working on #458, I noticed something strange with the URLs.
A line break was encoding to
%250A
, and a space would encode to%2520
, which doesn't seem right. Turns out special characters were being double encoded/decoded. This is mostly a waste of resources, but also increases the likelihood of a user running into #437 because it inflates the URL.It's also why all special characters had an encoding starting with
%25
. Because they were encoded already, so%
is the only possible special character, and then the%
got URI encoded to%25
.URLSearchParams already does URI encoding and decoding under the hood in
#set
and#get
. There's no need for us to do it!Here is a demonstration of the issue:
On libretranslate.com, if you insert
<
in the translation textarea, it currently becomes%253C
which is not the expected URI encoded string. It should be%3C
!