Bug #17029

URI.parse considers invalid when browsers consider it valid

Added by nileshtr (Nilesh Trivedi) about 1 month ago. Updated 23 days ago.

Target version:
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]


I have a form with <input type="url" required> and in the backend, I try to extract the domain with URI.parse(url).host

A user was able to submit a value like which passed the browser's validation check, but failed by URI.parse with this error:

        3: from /Users/helix/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/common.rb:234:in `parse'
        2: from /Users/helix/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/rfc3986_parser.rb:73:in `parse'
        1: from /Users/helix/.rbenv/versions/2.7.1/lib/ruby/2.7.0/uri/rfc3986_parser.rb:67:in `split'
URI::InvalidURIError (bad URI(is not URI?): "")

You can try the browser's behavior at MDN's demo:

This is what the MDN page says about validation:

The syntax of a URL is fairly intricate. It's defined by WHATWG's URL Living Standard ( ) and is described for newcomers in our article What is a URL? ( )

Updated by jeremyevans0 (Jeremy Evans) about 1 month ago

This does seem like a bug to me. It looks like should be an valid URL with a fragment of ##. However, the uri library is maintained in a separate repository. Please submit this as an issue to

Updated by phluid61 (Matthew Kerwin) about 1 month ago

It's not valid according to RFC 3986 (the URI standard) but that is pretty old now. I suspect switching from the IETF URI spec to the WHATWG URL spec would have other consequences, too.

Updated by nileshtr (Nilesh Trivedi) 27 days ago

I filed an issue at the uri library's Github repo:


Updated by jeremyevans0 (Jeremy Evans) 23 days ago

  • Status changed from Open to Closed

Also available in: Atom PDF