garycourt / uri-js

An RFC 3986 compliant, scheme extendable URI parsing/validating/normalizing/resolving library for JavaScript
Other
305 stars 69 forks source link

Resolving URNs with resolveComponents returns urn:undefined:undefined #38

Closed ucarion closed 4 years ago

ucarion commented 5 years ago

The following code:

var a = uri.serialize(uri.resolveComponents(uri.parse("urn:foo:bar:baz:quux"), uri.parse("")))
var b = uri.serialize(uri.resolveComponents(uri.parse(""), uri.parse("urn:foo:bar:baz:quux")))

console.log([a, b])

Outputs:

["urn:undefined:undefined", "urn:undefined:undefined"]

This seems like a bug, but perhaps I'm making an illogical request? This almost certainly seems related to: #26, although here it's with resolveComponents instead.

Runkit: https://runkit.com/embed/mf9pa43k4y9z

ucarion commented 5 years ago

Ah, also -- thanks for making this library. Truly an excellent piece of software. This issue is not at all pressing on my end, as I've found that URI.js seems to work better when I pass things around as strings than as URIComponents.

garycourt commented 4 years ago

You're welcome.

Having looked into this, the issue is that parsing a URN does not return the typical parts of a component, such as a path. Which is what resolveComponents is looking for but is not finding. In short, resolveComponents can not handle URN components.

You are better off using resolve instead of resolveComponents because it can handle this situation since it disables scheme specific parsing.