Skip to content

Commit

Permalink
fixes sporkmonger#268 Addressable::URI.heuristic_parse: uri starts wi…
Browse files Browse the repository at this point in the history
…th a digit and has specified port
  • Loading branch information
Mifrill committed Apr 16, 2018
1 parent b919fb0 commit 62af3ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/addressable/uri.rb
Expand Up @@ -194,6 +194,8 @@ def self.heuristic_parse(uri, hints={})
uri.sub!(/^file:\/+/i, "file:///")
when /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
uri.sub!(/^/, hints[:scheme] + "://")
else
uri = hints[:scheme] + "://" + uri if uri[/\A\d+\..*:\d+\z/]
end
match = uri.match(URIREGEX)
fragments = match.captures
Expand Down
14 changes: 13 additions & 1 deletion spec/addressable/uri_spec.rb
Expand Up @@ -5498,7 +5498,7 @@ def to_s
expect(uri.tld).to eq("uk")
end

context "witch " do
context "which " do
let (:uri) { Addressable::URI.parse("http://comrade.net/path/to/source/") }

it "contains a subdomain" do
Expand Down Expand Up @@ -6252,6 +6252,18 @@ def to_str
end
end

describe Addressable::URI, "when given the input " +
"'7777.example.org:8089'" do
before do
@input = "7777.example.org:8089"
end

it "should heuristically parse to 'http://7777.example.org:8089'" do
@uri = Addressable::URI.heuristic_parse(@input)
expect(@uri.to_s).to eq("http://7777.example.org:8089")
end
end

describe Addressable::URI, "when given the input " +
"'feed:///example.com'" do
before do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -18,4 +18,5 @@

RSpec.configure do |config|
config.warnings = true
config.filter_run_when_matching :focus
end

0 comments on commit 62af3ac

Please sign in to comment.