From c74b28d41572c2d20af4be9d717ed44635f154b0 Mon Sep 17 00:00:00 2001 From: Alexey Mahotkin Date: Tue, 17 Oct 2017 20:38:06 +0200 Subject: [PATCH] Always percent-encode special characters --- spec/linkhum-url.spec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/linkhum-url.spec b/spec/linkhum-url.spec index e4c65f8..eba23ef 100644 --- a/spec/linkhum-url.spec +++ b/spec/linkhum-url.spec @@ -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