ruby / uri

URI is a module providing classes to handle Uniform Resource Identifiers
https://ruby.github.io/uri/
Other
78 stars 42 forks source link

`register_scheme` does not comply with rfc2396 (or 3986) #89

Open doriantaylor opened 11 months ago

doriantaylor commented 11 months ago

RFC2396 § 3.1 states that the grammar for a URI scheme is:

      scheme        = alpha *( alpha | digit | "+" | "-" | "." )

whereas .register_scheme uses const_set and the grammar of Ruby constants is inconsistent with the grammar for a URI scheme:

  def self.register_scheme(scheme, klass)
    Schemes.const_set(scheme.to_s.upcase, klass)
  end

How much trouble would it be to switch to a Hash keyed by Symbols, so that it's possible to register (compliant) URI schemes with hyphens, + signs, dots?

duerst commented 11 months ago

How many schemes are there that actually use a '.'?

doriantaylor commented 11 months ago

The answer is fourteen:

$ curl -s https://www.iana.org/assignments/uri-schemes/uri-schemes.txt | sed -n '/^\([a-z][^ ]*\)/ s/\([^[:space:]]*\).*/\1/ p' | grep '\.' | wc -l
$ 14

…along with five that contain a + and 81 that contain a -.