URI.js icon indicating copy to clipboard operation
URI.js copied to clipboard

Parsing of non urn-urn like URIs

Open leipert opened this issue 8 years ago • 3 comments

Hey there. First off: Greate Library, saved us a ton of work.

I just found a small inconsistency/naming issue:

URI.parse('mailto:[email protected]')
/* returns
{
	path: "[email protected]",
	protocol: "mailto",
	urn: true,
}
*/

(Executable in the browser here)

I understand that in URI.js everything that is an not an url (aka missing the authority) is marked as an urn, which is not quite right, as the urn spec defines, that a urn starts with urn:.

My proposal would be that internally instead of urn, url would be used:

URI.parse('mailto:[email protected]')
/* returns
{ url: false, ... }
*/

URI.parse('http://google.com')
URI.parse('/relative/path')
/* returns
{ url: true, ... }
*/

leipert avatar Jan 09 '17 15:01 leipert

RFC3986 section 1.1.3: The term "Uniform Resource Name" (URN) has been used historically to refer to both URIs under the "urn" scheme RFC2141, which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name.

As far as I can tell URI.js does not deal with URNs as specified by RFC2141. Within URI.js the term URN is used in the second sense of the definition: »… to any other URI with the properties of a name«.

I can see how this is confusing. What exactly are you trying to achieve that you need the flag urn: true be renamed to url: false?

rodneyrehm avatar Jan 09 '17 15:01 rodneyrehm

Ha, thanks for that section.

I just thought it would make more sense in a for API consistency. And to

The docs state, that

.is("urn") // true if URI looks like a URN

and I really like the wording "like a URN".

Maybe just rename it to urnLike or if you prefer not changing the API, simply adding a few sentences to the docs would be enough.

Would you like a merge requests with a few docs improvements? As far as I see, the docs mention "URN" only two times in the API documentation. Especially ".parse" and ".segments" may be missing examples.

leipert avatar Jan 09 '17 19:01 leipert

Would you like a merge requests with a few docs improvements?

you know I do ;)

rodneyrehm avatar Jan 09 '17 19:01 rodneyrehm