fix(platform): preserve percent encoding in Url.setUrlParams and modifyUrlParams#6154
Open
Gdhanush-13 wants to merge 1 commit intoEffect-TS:mainfrom
Open
fix(platform): preserve percent encoding in Url.setUrlParams and modifyUrlParams#6154Gdhanush-13 wants to merge 1 commit intoEffect-TS:mainfrom
Gdhanush-13 wants to merge 1 commit intoEffect-TS:mainfrom
Conversation
…fyUrlParams UrlParams.toString uses URLSearchParams.toString() which converts %20 to + per the application/x-www-form-urlencoded spec. This is correct for form bodies but wrong for URL query strings where %20 encoding should be preserved. Added UrlParams.toPercentEncoded which uses encodeURIComponent (producing %20 for spaces) and use it in Url.setUrlParams and Url.modifyUrlParams. The existing toString is left unchanged for backward compatibility with form body encoding. Fixes Effect-TS#6153
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Fixes #6153 -
Url.modifyUrlParamsconverts%20to+in query parameters, even when using an identity function.Root Cause
Url.setUrlParamsandUrl.modifyUrlParamsboth useUrlParams.toStringto serialize params back to a search string.UrlParams.toStringdelegates tonew URLSearchParams(...).toString()which encodes spaces as+per theapplication/x-www-form-urlencodedspec. This is correct for form request bodies but wrong for URL query strings where%20should be preserved.Reproduction
Fix
UrlParams.toPercentEncodedwhich usesencodeURIComponent(producing%20for spaces)Url.setUrlParamsandUrl.modifyUrlParamsto usetoPercentEncodedinstead oftoStringUrlParams.toStringunchanged for backward compatibility withapplication/x-www-form-urlencodedbody encodingFiles Changed
packages/platform/src/UrlParams.ts- addedtoPercentEncodedpackages/platform/src/Url.ts- usetoPercentEncodedinsetUrlParamsandmodifyUrlParams