Skip to content

Commit

Permalink
Always percent-encode special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
squadette committed Oct 17, 2017
1 parent fb070f7 commit c74b28d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions spec/linkhum-url.spec
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ describe Linkhum::URL do
end

["%", "#", "?", "&", "+", "[", "]"].each do |char|
encoded_char = URI.encode_www_form_component(char)

it "handles percent-encoded #{char} symbol in path" do
encoded = URI.encode(char)
url = "http://example.com/#{encoded}"
url = "http://example.com/#{encoded_char}"
lu = Linkhum::URL.parse(url)
expect(lu[:human_readable]).to eql("http://example.com/#{char}")
expect(lu[:url_encoded]).to eql("http://example.com/#{encoded}")
expect(lu[:url_encoded]).to eql("http://example.com/#{encoded_char}")
end

it "handles percent-encoded #{char} symbol in query" do
encoded = URI.encode_www_form_component(char)
url = "http://example.com/?query=#{encoded}"
url = "http://example.com/?query=#{encoded_char}"
lu = Linkhum::URL.parse(url)
expect(lu[:human_readable]).to eql("http://example.com/?query=#{char}")
expect(lu[:url_encoded]).to eql("http://example.com/?query=#{encoded}")
expect(lu[:url_encoded]).to eql("http://example.com/?query=#{encoded_char}")
end
end

Expand Down

0 comments on commit c74b28d

Please sign in to comment.