Skip to content

Instantly share code, notes, and snippets.

@lengarvey
Last active December 4, 2017 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lengarvey/c1d17913f9ea95fd999c to your computer and use it in GitHub Desktop.
Save lengarvey/c1d17913f9ea95fd999c to your computer and use it in GitHub Desktop.
URI.parse issue with ruby-trunk.
irb(main):014:0* url = "https://bugs.ruby-lang.org/projects/ruby-trunk/issues?set_filter=1&f[]=status_id&op[status_id]=o"
=> "https://bugs.ruby-lang.org/projects/ruby-trunk/issues?set_filter=1&f[]=status_id&op[status_id]=o"
irb(main):015:0> URI.encode url
=> "https://bugs.ruby-lang.org/projects/ruby-trunk/issues?set_filter=1&f[]=status_id&op[status_id]=o"
irb(main):016:0> URI.parse url
URI::InvalidURIError: bad URI(is not URI?): https://bugs.ruby-lang.org/projects/ruby-trunk/issues?set_filter=1&f[]=status_id&op[status_id]=o
from /Users/artega/.rubies/ruby-trunk/lib/ruby/2.2.0/uri/rfc3986_parser.rb:47:in `split'
from /Users/artega/.rubies/ruby-trunk/lib/ruby/2.2.0/uri/rfc3986_parser.rb:53:in `parse'
from /Users/artega/.rubies/ruby-trunk/lib/ruby/2.2.0/uri/common.rb:223:in `parse'
from (irb):16
from /Users/artega/.rubies/ruby-trunk/bin/irb:11:in `<main>'
@lengarvey
Copy link
Author

The problem is caused by URI.parse using the new URI::RFC3896_Parser but URI.encode uses the old URI::RFC2396_Parser.

@lengarvey
Copy link
Author

URI::RFC3896_Parser doesn't implement #escape so there isn't a straightforward solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment