Closed
Description
- Version: 14.13.0
- Platform: all
- Subsystem: url
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 use http://localhost:3000//
in Firefox) this fails with ERR_INVALID_URL
.
If the deprecated url.parse()
is used it works.
Standalone reproducer:
const http = require("http")
const port = 3000
const server = http.createServer((req, res) => {
console.log("pathname:", new URL(req.url, `http://${req.headers.host}`).pathname)
res.end()
}).listen(port, () => http.get({ port, path: "//" }))
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 using URL
for parsing relative urls has some pitfalls.