Skip to content

Commit

Permalink
Merge pull request #262 from dentarg/case-insensitive-scheme-in-reque…
Browse files Browse the repository at this point in the history
…st_uri

Request URI methods: handle URI with uppercase letters in scheme
  • Loading branch information
sporkmonger committed Jul 24, 2017
2 parents 279dbaf + 09f7234 commit 6aa1b8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ def query_values=(new_query_values)
#
# @return [String] The request URI required for an HTTP request.
def request_uri
return nil if self.absolute? && self.scheme !~ /^https?$/
return nil if self.absolute? && self.scheme !~ /^https?$/i
return (
(!self.path.empty? ? self.path : SLASH) +
(self.query ? "?#{self.query}" : EMPTY_STR)
Expand All @@ -1739,7 +1739,7 @@ def request_uri=(new_request_uri)
if !new_request_uri.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_request_uri.class} into String."
end
if self.absolute? && self.scheme !~ /^https?$/
if self.absolute? && self.scheme !~ /^https?$/i
raise InvalidURIError,
"Cannot set an HTTP request URI for a non-HTTP URI."
end
Expand Down
10 changes: 7 additions & 3 deletions spec/addressable/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ def to_s
expect(@uri.normalize.query).to eq("a=1")
end

it "returns '/%70a%74%68?a=%31' for #request_uri" do
expect(@uri.request_uri).to eq("/%70a%74%68?a=%31")
end

it "returns '1%323' for #fragment" do
expect(@uri.fragment).to eq("1%323")
end
Expand Down Expand Up @@ -1971,9 +1975,9 @@ def to_s

# Section 5.1.2 of RFC 2616
describe Addressable::URI, "when parsed from " +
"'http://www.w3.org/pub/WWW/TheProject.html'" do
"'HTTP://www.w3.org/pub/WWW/TheProject.html'" do
before do
@uri = Addressable::URI.parse("http://www.w3.org/pub/WWW/TheProject.html")
@uri = Addressable::URI.parse("HTTP://www.w3.org/pub/WWW/TheProject.html")
end

it "should have the correct request URI" do
Expand Down Expand Up @@ -2008,7 +2012,7 @@ def to_s

it "should correctly convert to a hash" do
expect(@uri.to_hash).to eq({
:scheme => "http",
:scheme => "HTTP",
:user => nil,
:password => nil,
:host => "www.w3.org",
Expand Down

0 comments on commit 6aa1b8a

Please sign in to comment.