-
Notifications
You must be signed in to change notification settings - Fork 327
Description
I've encountered InvalidURIError error when dealing with the redirects to a location with // path. (e.g. https://google.com//).
After further investigation, I realized that HTTP doesn't allow to make a request to such urls at all.
The crux of the matter is HTTP::Request#headline method that uses Addressable::URI#omit method to get the path + query portion of the given url.
And while addressable allows to parse such urls http://google.com// and most of the methods work as expected, it fails with InvalidURIError when uri.omit(:authority) is called.
Relevant line in Addressable source code: https://github.com/sporkmonger/addressable/blob/8f4fee07243af0b788c625e59a9ca529489336d6/lib/addressable/uri.rb#L2427
Steps to reproduce
HTTP.get("https://google.com//")
#Addressable::URI::InvalidURIError: Cannot have a path with two leading slashes without anauthority set: '//'Reproducing with Addressable directly:
# Parse url with // path
url = Addressable::URI.parse("https://google.com//")
# Check that it works as expected
url.path == "//"
# Try to remove authority
url.omit(:authority) # raises InvalidURIErrorI was going to submit this issue to the addressable repository at first, but after the consideration I think that it's primarily the bug in HTTP.
Because Addressable is following the spec that disallows path with two leading slashes without the authority.
Ruby version: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
Gem version: http (2.1.0) and addressable (2.5.0)