3 ms·
`URL` in node and browser is supposed to be compatible, this looks like a bug (browser ignoring protocols they don't know).
by silverwind 3y ago
`URL` in node and browser is supposed to be compatible, this looks like a bug (browser ignoring protocols they don't know).
- cxr 3y agoURL parsing semantics are defined by and dependent upon the scheme. (That's spec.) By definition, if you don't recognize the scheme, you cannot guarantee a correctly parsed URL. From RFC 1738: 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.
- bkallus 3y agoRFC 3986 provides a generic URI grammar that is not scheme-specific, though other standards that define URL schemes may choose to subset the subset that grammar as they see fit. If a URL parser does not recognize a scheme, I would expect it to parse the URL using the generic parsing procedure.
- cxr 3y agoWell, they don't. Browsers implement the WHATWG's spec, which says not to do that and was created to supersede RFC 3986.