Are URI's with a double hash (##) invalid?
Asked Answered
K

3

5

I have URI that contains ## (e.g. http://foo.com/bar##baz) . Ruby's URI.parse function throws an error when I try to parse it.

Are double hash marks forbidden in URIs? Or is the Ruby Parser too strict?

Kept answered 11/6, 2013 at 22:57 Comment(1)
possible duplicate of Multiple fragment identifiers correct in URL?Wallas
L
13

Fragment Identifiers may not contain a hash sign. The parser is correct.

The syntax for a fragment identifier is defined as follows:

fragment = *( pchar / "/" / "?" )

pchar is defined as:

pchar = unreserved / pct-encoded / sub-delims / ":" / "@"

unreserved, pct-encoded and sub-delims are defined as:

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"

pct-encoded = "%" HEXDIG HEXDIG

sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
Lenticular answered 11/6, 2013 at 23:12 Comment(0)
S
3

They are invalid. A # indicates that the remainder is a fragment, and a fragment may not have a # in it.

Stillmann answered 11/6, 2013 at 23:12 Comment(0)
B
0

Addressable allows it:

require 'addressable/uri'
Addressable::URI.parse('http://foo.com/bar##baz').fragment
#=> "#baz"

Addressable is supposed to conform more closely to the rfc's, but wko knows. I would say it's subject to interpretation.

Britisher answered 12/6, 2013 at 0:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.