-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
using Whatwg url to parse relative urls received via http may fail #35458
Comments
What are the input values for |
it seems like |
We really need to just add a separate class for http request url formats. whatwg urls are not made for it. |
Thank you for finding this. I just quickly checked with the latest reference implementation of URL and could reproduce the same error. However, it works with That being said we can pass const http = require("http")
const port = 3000
const server = http.createServer((req, res) => {
console.log("pathname:", new URL(`http://${req.headers.host}${req.url}`).pathname)
res.end()
}).listen(port, () => http.get({ port, path: "//" }))
/*
=> pathname: //
*/ |
Before building an absolute url it's needed to verify that the recevied url is relative. Absolute urls are also possible in HTTP (see https://tools.ietf.org/html/rfc7230#section-5.3) |
Should we consider to adapt to to use Which usecase will not work if |
Generally speaking we're continuing to use |
Unfortunately, |
Closing this issue, since this is the intended behavior according to WHATWG URL specification. |
What steps will reproduce the bug?
I used
new URL()
to parse the relative url received by my HTTP server as indicated in the docs. If the relative url is//
(e.g. I usehttp://localhost:3000//
in Firefox) this fails withERR_INVALID_URL
.If the deprecated
url.parse()
is used it works.Standalone reproducer:
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
parsing works
What do you see instead?
parsing fails
Additional information
I'm not sure if this is a problem in
URL
parser. In case the URL parser is working as intended the doc should give some hints that usingURL
for parsing relative urls has some pitfalls.Refs: #34978
Refs: #30830
The text was updated successfully, but these errors were encountered: