From 726a377a1c2d2267a0c7f88dc0c92ad6d6105a6d Mon Sep 17 00:00:00 2001 From: Aleksey Strizhak Date: Mon, 16 Apr 2018 11:34:07 +0500 Subject: [PATCH] fixes #268 Addressable::URI.heuristic_parse: uri starts with a digit and has specified port --- lib/addressable/uri.rb | 2 ++ spec/addressable/uri_spec.rb | 14 +++++++++++++- spec/spec_helper.rb | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index ce5726f4..6a9ce5d6 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -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 diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index e4fe5d90..748fb568 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0b538298..0813f79b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,4 +18,5 @@ RSpec.configure do |config| config.warnings = true + config.filter_run_when_matching :focus end