garycourt / uri-js

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

Incorrect parsed scheme #23

Closed jsumners closed 6 years ago

jsumners commented 6 years ago

Given urn:oasis:names:tc:SAML:2.0:assertion as the URI, the result of .parse is:

{ scheme: 'urn:oasis',
  userinfo: undefined,
  host: undefined,
  port: undefined,
  path: 'names:tc:SAML:2.0:assertion',
  query: undefined,
  fragment: undefined,
  reference: 'absolute' }

This is incorrect. The scheme should be urn and the path should be oasis:names:tc:SAML:2.0:assertion.

garycourt commented 6 years ago

No, it's correct. urn can not be a scheme on it's own. See RFC 2141 Section 2.

jsumners commented 6 years ago

Um, your citation is exactly saying that urn is the scheme:

All URNs have the following syntax (phrases enclosed in quotes are REQUIRED):

                <URN> ::= "urn:" <NID> ":" <NSS>

where is the Namespace Identifier, and is the Namespace Specific String. The leading "urn:" sequence is case-insensitive. The Namespace ID determines the syntactic interpretation of the Namespace Specific String (as discussed in [1]).

Further, see https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Examples

  urn:example:mammal:monotreme:echidna
  └┬┘ └──────────────┬───────────────┘
scheme              path
garycourt commented 6 years ago

Actually, you're right. RFC 2141 Appendix A states:

The URN syntax has been defined so that URNs can be used in places where URLs are expected. A resolver that conforms to the current URL syntax specification [3] will extract a scheme value of "urn:" rather than a scheme value of "urn:\<nid>".

My confusion was that <URN> (which includes <NID>) was the scheme. I'll try to get to it in the next couple days.

jsumners commented 6 years ago

I understand. It's a very confusing bit of the spec. I'm only versed on it currently because I'm digging in to SAML garbage.

garycourt commented 6 years ago

This has now been fixed.