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
searchParams without base url break #228
Comments
Can you include an example of the code (your usage) that used to work? |
Sure,
Should result in But ends up throwing the following error: |
I cannot reproduce this in a browser, however there are conditions under which this can happen. We still respect the document base URL, we just rely on Server-side runtimes and Now, given that (annoyingly) relative URLs are not supported by However, it's worth noting that:
I'm not sure exactly why this would be happening to you with The only reliable fix for this that I can think of is to hack around the if (this._options.searchParams) {
const fakeBaseUrl = 'https://fake-host.invalid';
const url = new URL(this.request.url, fakeBaseUrl);
url.search = new URLSearchParams(this._options.searchParams);
// Convert the URL back to a relative URL if it was previously relative.
// We only needed an absolute URL due to limitations in `new URL()`
if (url.origin === fakeBaseUrl) {
url = url.pathname + url.search + url.hash;
}
this.request = new globals.Request(new globals.Request(url, this.request), this._options);
} It's not clear to me what host would be used in such an environment where this code path would help, but hopefully the Also, this hack scares me a bit. I'd be worried that data would somehow accidentally get sent to the wrong host, which would be a security nightmare. We could have a good test suite around this behavior, but I can't say I'm excited about it. |
Thanks for looking into it Seth, looks like the issue is not with ky, but with the mock environment we use and due to it working in the previous version I made the wrong conclusion. You are right, its definitely due to an out of date implementation of Request in this case, not pure browser implementation. Your suggestions are interesting, and could definitely be useful in my specific mock case, but lets close this issue off. |
Hi,
So before 0.16, optional searchParams would use the browser base to create a new URL, now this is not the case so there is no way to use searchParams as I see it without fully realized url string.
Am I using this wrong or is this an issue for anyone else?
ky/index.js
Line 240 in bb46ca8
The text was updated successfully, but these errors were encountered: