-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: url.search is a string so do not set it as a URLSearchParams #103
Conversation
Updates the types to make transformSearchParams return a string and adds a test.
@@ -41,7 +41,7 @@ export interface HTTPOptions extends FetchOptions { | |||
/** | |||
* Transform search params | |||
*/ | |||
transformSearchParams?: (params: URLSearchParams) => URLSearchParams | |||
transformSearchParams?: (params: URLSearchParams) => string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its safer to work with a URLSearchParams instance, so why return a string here ? we can call .toString internally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that URLSearchParams
is a better representation to work with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to work around the way go-IPFS expects binary data to be URL encoded (see ipfs/kubo#7939 for context).
In a nutshell 0xFE
(decimal 254) needs to be encoded as %FE
and not %C3%BE
, so I was doing the encoding myself but if you have to pass back a URLSearchParams
instance, it'll re-encode the data, which makes it garbage on the server when it's decoded.
I don't think it's necessarily the way to go, since now everyone has to use a custom encoder/decoder - instead we should be able to pass base64 encoded data to the HTTP API if it has to go on the query string, but the fact that we have to @ts-ignore
the assignment here seemed a bit weird.
URL.search
is a string, and the return type of transformSearchParams
gets turned into a string when it is assigned to URL.search
so why not let the user return a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im good with the internal change to assign strings to search
just not the return type change.
I know transformSearchParams
is basically just for our use but keeping the return type URLSearchParams
will be at least a reminder to not manually encoded querystrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping the return type URLSearchParams will be at least a reminder to not manually encoded querystrings.
The thing is, I needed to manually encode a query string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah lol, if we can avoid that lets ship this
Does not seem to be relevant anymore, feel free to open new one if needed. |
Updates the types to make transformSearchParams return a string and adds a test.