Skip to content

Commit

Permalink
Merge 56743c7 into 29e26cc
Browse files Browse the repository at this point in the history
  • Loading branch information
EiNSTeiN- committed Sep 24, 2015
2 parents 29e26cc + 56743c7 commit f5bed32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/addressable/uri.rb
Expand Up @@ -44,6 +44,7 @@ module CharacterClasses
UNRESERVED = ALPHA + DIGIT + "\\-\\.\\_\\~"
PCHAR = UNRESERVED + SUB_DELIMS + "\\:\\@"
SCHEME = ALPHA + DIGIT + "\\-\\+\\."
HOST = ALPHA + DIGIT + "\\-\\.\\[\\:\\]"
AUTHORITY = PCHAR
PATH = PCHAR + "\\/"
QUERY = PCHAR + "\\/\\?"
Expand Down Expand Up @@ -1075,6 +1076,9 @@ def normalized_host
# Single trailing dots are unnecessary.
result = result[0...-1]
end
result = Addressable::URI.normalize_component(
result,
CharacterClasses::HOST)
result
else
EMPTY_STR
Expand All @@ -1094,7 +1098,7 @@ def host=(new_host)

unreserved = CharacterClasses::UNRESERVED
sub_delims = CharacterClasses::SUB_DELIMS
if @host != nil && (@host =~ /[<>{}\/\?\#\@"]/ ||
if @host != nil && (@host =~ /[<>{}\/\?\#\@"[[:space:]]]/ ||
(@host[/^\[(.*)\]$/, 1] != nil && @host[/^\[(.*)\]$/, 1] !~
Regexp.new("^[#{unreserved}#{sub_delims}:]*$")))
raise InvalidURIError, "Invalid character in host: '#{@host.to_s}'"
Expand Down
34 changes: 34 additions & 0 deletions spec/addressable/uri_spec.rb
Expand Up @@ -168,6 +168,40 @@ def to_s
end
end

describe Addressable::URI, "newline normalization" do
it "should not unescape newline in scheme" do
uri = Addressable::URI.parse("ht%0atp://localhost/").normalize
expect(uri.to_s).to eq("ht%0Atp://localhost/")
end

it "should not unescape newline in path" do
uri = Addressable::URI.parse("http://localhost/%0a").normalize
expect(uri.to_s).to eq("http://localhost/%0A")
end

it "should not unescape newline in hostname" do
uri = Addressable::URI.parse("http://local%0ahost/").normalize
expect(uri.to_s).to eq("http://local%0Ahost/")
end

it "should not unescape newline in username" do
uri = Addressable::URI.parse("http://foo%0abar@localhost/").normalize
expect(uri.to_s).to eq("http://foo%0Abar@localhost/")
end

it "should not unescape newline in username" do
uri = Addressable::URI.parse("http://example:foo%0abar@localhost/").normalize
expect(uri.to_s).to eq("http://example:foo%0Abar@localhost/")
end

it "should not accept newline in hostname" do
uri = Addressable::URI.parse("http://localhost/")
expect(lambda do
uri.host = "local\nhost"
end).to raise_error(Addressable::URI::InvalidURIError)
end
end

describe Addressable::URI, "when created with ambiguous path" do
it "should raise an error" do
expect(lambda do
Expand Down

0 comments on commit f5bed32

Please sign in to comment.