Pregunta

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?

¿Fue útil?

Solución

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  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

Otros consejos

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

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top