Skip to content

Commit

Permalink
Merge pull request #296 from Mifrill/issue_268
Browse files Browse the repository at this point in the history
fixes #268 Addressable::URI.heuristic_parse: uri starts with a digit …
  • Loading branch information
sporkmonger committed May 31, 2018
2 parents b919fb0 + f93be25 commit ed48536
Show file tree
Hide file tree
Showing 2 changed files with 15 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] + "://")
when /\A\d+\..*:\d+\z/
uri = "#{hints[:scheme]}://#{uri}"
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 which "\
"start with digits and has specified port" 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

0 comments on commit ed48536

Please sign in to comment.