summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2014-11-28 12:16:51 +0000
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2014-11-28 13:16:50 +0000
commit31576ab0ec01c698fa2bd8c6ebcccd6468d0bcff (patch)
tree50ef025b548b812b896117a62deb49573937911d
parent3ad740754507629a73525ffdcc0b3eb06f177001 (diff)
downloadchef-kwilczynski/http-create-url.tar.gz
Fix. Make sure that scheme part of the URI is treated in a case-insensitive manner.kwilczynski/http-create-url
This is as per http://en.wikipedia.org/wiki/URI_scheme, and solves some edges i.e., following (30x) URL from the "Location" header where we have to deal with "HTTP://". Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--lib/chef/http.rb2
-rw-r--r--spec/unit/http_spec.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 8d00a38dc1..5e52337aff 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -203,7 +203,7 @@ class Chef
def create_url(path)
return path if path.is_a?(URI)
- if path =~ /^(http|https):\/\//
+ if path =~ /^(http|https):\/\//i
URI.parse(path)
elsif path.nil? or path.empty?
URI.parse(@url)
diff --git a/spec/unit/http_spec.rb b/spec/unit/http_spec.rb
index 60d36eb4a0..ddfc56583d 100644
--- a/spec/unit/http_spec.rb
+++ b/spec/unit/http_spec.rb
@@ -44,6 +44,13 @@ describe Chef::HTTP do
expect(http.create_url('///api/endpoint?url=http://foo.bar')).to eql(URI.parse('http://www.getchef.com/organization/org/api/endpoint?url=http://foo.bar'))
end
+ # As per: https://github.com/opscode/chef/issues/2500
+ it 'should treat scheme part of the URI in a case-insensitive manner' do
+ http = Chef::HTTP.allocate # Calling Chef::HTTP::new sets @url, don't want that.
+ expect { http.create_url('HTTP://www1.chef.io/') }.not_to raise_error
+ expect(http.create_url('HTTP://www2.chef.io/')).to eql(URI.parse('http://www2.chef.io/'))
+ end
+
end # create_url
describe "head" do