new URL('postgres://user:pass@host/db')
Node parses this as if it were a web address, into protocol, username, password, host, pathname, etc.Browsers just parse out the protocol and call everything else a pathname.
new URL('postgres://user:pass@host/db')
Node parses this as if it were a web address, into protocol, username, password, host, pathname, etc.Browsers just parse out the protocol and call everything else a pathname.
They used to do the protocol, username, password, host, pathname, etc. But scammers used it to have a user name that looked like a well-known URL, while actually directing the user to a domain under the scammer's control. Not honoring the spec was therefore a security feature.
/<user>:<password>@<host>:<port>/<url-path>
Which means if you're presented with that and don't send it to that host, you've violated the RFC. But this was demonstrably resulting in confused users being sent to scammer's domains.The Internet Assigned Numbers Authority (IANA) will maintain a registry of URL schemes. Any submission of a new URL scheme must include a definition of an algorithm for accessing of resources within that scheme and the syntax for representing such a scheme.
The behavior described (extracting the scheme and treating the rest as an opaque string) is pretty much the only thing you can do when the scheme is unrecognized. (The other options being to throw an exception or return null.)
Based on the description, it sounds like neither are breaking spec—it's just that Node supports "postgres". That is, unless it's true that Node's URL implementation is supposed to match what browsers do, in which case Node is breaking spec—its own.