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

URI.parse can blow up with non-standard URIs #487

Closed
matthewrudy opened this issue Nov 22, 2013 · 3 comments
Closed

URI.parse can blow up with non-standard URIs #487

matthewrudy opened this issue Nov 22, 2013 · 3 comments

Comments

@matthewrudy
Copy link
Contributor

Here's an example tweet_spec that fails with URI

it "can handle strange urls" do
  urls_array = [
    {
      :url => "http://with_underscore.example.com/t.co",
      :expanded_url => "http://with_underscore.example.com/expanded",
      :display_url => "with_underscore.example.com/expanded…",
      :indices => [10, 33],
    }
  ]
  tweet = Twitter::Tweet.new(:id => 28669546014, :entities => {:urls => urls_array})
  uri = tweet.uris.first
  expect{ uri.url }.to_not raise_error
  expect{ uri.expanded_url }.to_not raise_error
  expect{ uri.display_url }.to_not raise_error
end

It fails with;

Failure/Error: expect{ uri.url }.to_not raise_error
       expected no Exception, got #<URI::InvalidURIError: the scheme http does not accept registry part: with_underscore.example.com (or bad hostname?)> with backtrace:
         # ./lib/twitter/base.rb:77:in `block in define_uri_method'
         # ./spec/twitter/tweet_spec.rb:325:in `block (4 levels) in <top (required)>'
         # ./spec/twitter/tweet_spec.rb:325:in `block (3 levels) in <top (required)>'
@sferik
Copy link
Owner

sferik commented Nov 28, 2013

Technically, hostnames that contain underscores are not valid, so Ruby’s built-in URI library refuses to parse them. The addressable gem does a better job of handling some of these invalid-but-exist-in-the-real-world edge cases.

@sferik sferik closed this as completed in 7ea2f53 Nov 28, 2013
@matthewrudy
Copy link
Contributor Author

that's great, thanks.

@sferik
Copy link
Owner

sferik commented Nov 28, 2013

Try upgrading to version 5.0.1. That ought to fix it.

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

No branches or pull requests

2 participants