FIX: preserve fragment identifier when escaping url

This commit is contained in:
Arpit Jalan 2017-07-29 17:20:22 +05:30
parent da5e7dc876
commit 1fe553873c
2 changed files with 9 additions and 2 deletions

View File

@ -12,7 +12,7 @@ class FinalDestination
def initialize(url, opts = nil)
@uri =
begin
URI(URI.escape(url)) if url
URI(URI.escape(CGI.unescapeHTML(url), Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}#]"))) if url
rescue URI::InvalidURIError
end

View File

@ -62,12 +62,19 @@ describe FinalDestination do
it "escapes url" do
url = 'https://eviltrout.com?s=180&d=mm&r=g'
escaped_url = URI.escape(url)
escaped_url = URI.escape(CGI.unescapeHTML(url), Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}#]"))
stub_request(:head, escaped_url).to_return(doc_response)
expect(fd(url).resolve.to_s).to eq(escaped_url)
end
it "preserves url fragment identifier" do
url = 'https://eviltrout.com/2016/02/25/fixing-android-performance.html#discourse-comments'
stub_request(:head, 'https://eviltrout.com/2016/02/25/fixing-android-performance.html').to_return(doc_response)
expect(fd(url).resolve.to_s).to eq(url)
end
it "returns the final url" do
final = FinalDestination.new('https://eviltrout.com', opts)
expect(final.resolve.to_s).to eq('https://eviltrout.com')