Skip to content

Commit

Permalink
Fixed issue with percent escaping characters 0-15.
Browse files Browse the repository at this point in the history
  • Loading branch information
sporkmonger committed Jan 29, 2009
1 parent 6fb070f commit 08bc542
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/addressable/uri.rb
Expand Up @@ -958,7 +958,7 @@ def self.encode_component(component, character_class=
character_class = /[^#{character_class}]/
end
return component.gsub(character_class) do |sequence|
(sequence.unpack('C*').map { |c| "%#{c.to_s(16).upcase}" }).join("")
(sequence.unpack('C*').map { |c| "%" + ("%02x" % c).upcase }).join("")
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/addressable/uri_spec.rb
Expand Up @@ -3617,6 +3617,18 @@ def to_str
end
end

describe Addressable::URI, "when encoding a string with ASCII chars 0-15" do
it "should result in correct percent encoded sequence" do
Addressable::URI.encode_component("one\ntwo").should == "one%0Atwo"
end

it "should result in correct percent encoded sequence" do
Addressable::URI.encode_component(
"one\ntwo", /[^a-zA-Z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\-\.\_\~]/
).should == "one%0Atwo"
end
end

describe Addressable::URI, "when unencoding a multibyte string" do
it "should result in correct percent encoded sequence" do
Addressable::URI.unencode_component("g%C3%BCnther").should == "günther"
Expand Down

0 comments on commit 08bc542

Please sign in to comment.