Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressable::URI::InvalidURIError (Hostname not supplied: '') when using omit #363

Open
noff opened this issue Oct 24, 2019 · 5 comments
Open
Labels

Comments

@noff
Copy link

noff commented Oct 24, 2019

Hello. Here is an example:

Addressable::URI.parse("https://user:password@dev.domain.com").omit(:scheme, :port, :user, :password, :host)
Traceback (most recent call last):
        1: from (irb):22
Addressable::URI::InvalidURIError (Hostname not supplied: '')

It raises only with omit method.

When try to parse URL and use an object, everything works great:

u = Addressable::URI.parse("https://user:password@dev.domain.com").
u.path
=> ""
@dentarg
Copy link
Collaborator

dentarg commented Oct 24, 2019

@noff what version of Addressable are you using?

@noff
Copy link
Author

noff commented Oct 24, 2019

addressable (~> 2.3, >= 2.3.8)

@noff
Copy link
Author

noff commented Oct 24, 2019

Just updated to addressable (2.7.0), same issue

@dentarg
Copy link
Collaborator

dentarg commented Jul 15, 2021

Addressable::URI.parse("https://user:password@dev.domain.com").omit(:scheme, :port, :user, :password, :host)

@noff what do you expect this to return?

This?

irb(main):009:0> Addressable::URI.parse("")
=> #<Addressable::URI:0x168 URI:>

Tested this myself with a few variants, seems to only trigger with username/password in the URL

irb(main):016:0> Addressable::URI.parse("https://foo.com").omit(:scheme)
=> #<Addressable::URI:0x1e0 URI://foo.com>
irb(main):017:0> Addressable::URI.parse("https://foo.com").omit(:scheme, :host)
=> #<Addressable::URI:0x1f4 URI:>
irb(main):018:0> Addressable::URI.parse("https://foo.com").omit(:scheme, :port, :host)
=> #<Addressable::URI:0x208 URI:>
irb(main):019:0> Addressable::URI.parse("https://foo.com").omit(:scheme, :port, :user, :host)
=> #<Addressable::URI:0x21c URI:>
irb(main):020:0> Addressable::URI.parse("https://foo.com").omit(:scheme, :port, :user, :password, :host)
=> #<Addressable::URI:0x230 URI:>
irb(main):021:0> Addressable::URI.parse("https://foo@foo.com").omit(:scheme, :port, :user, :password, :host)
=> #<Addressable::URI:0x244 URI:>
irb(main):022:0> Addressable::URI.parse("https://foo:bar@foo.com").omit(:scheme, :port, :user, :password, :host)
Traceback (most recent call last):
        7: from /Users/dentarg/.rubies/ruby-2.7.3/bin/irb:23:in `<main>'
        6: from /Users/dentarg/.rubies/ruby-2.7.3/bin/irb:23:in `load'
        5: from /Users/dentarg/.rubies/ruby-2.7.3/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        4: from (irb):22
        3: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2327:in `omit'
        2: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2421:in `defer_validation'
        1: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2483:in `validate'
Addressable::URI::InvalidURIError (Hostname not supplied: '')

I wonder if this is a similar bug? (similar error as in #272)

irb(main):015:0> Addressable::URI.parse("https://foo.com").omit(:host)
Traceback (most recent call last):
        7: from /Users/dentarg/.rubies/ruby-2.7.3/bin/irb:23:in `<main>'
        6: from /Users/dentarg/.rubies/ruby-2.7.3/bin/irb:23:in `load'
        5: from /Users/dentarg/.rubies/ruby-2.7.3/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        4: from (irb):15
        3: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2327:in `omit'
        2: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2421:in `defer_validation'
        1: from /Users/dentarg/.gem/ruby/2.7.3/gems/addressable-2.8.0/lib/addressable/uri.rb:2476:in `validate'
Addressable::URI::InvalidURIError (Absolute URI missing hierarchical segment: 'https:')

@dentarg dentarg changed the title Hostname not supplied Addressable::URI::InvalidURIError (Hostname not supplied: '') when using omit Jul 15, 2021
@noff
Copy link
Author

noff commented Jul 16, 2021

@dentarg
It will be great if omit host won't raise error. Like this:

Addressable::URI.parse("https://foo.com/mypath").omit(:host).path
=> "/mypath"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants