FIX: Escape URL before attempting to resolve it.

This commit is contained in:
Guo Xiang Tan 2017-07-18 10:04:24 +09:00
parent 089a1bd3be
commit b534778f46
2 changed files with 9 additions and 1 deletions

View File

@ -12,7 +12,7 @@ class FinalDestination
def initialize(url, opts=nil)
@uri =
begin
URI(url) if url
URI(URI.escape(url)) if url
rescue URI::InvalidURIError
end

View File

@ -60,6 +60,14 @@ describe FinalDestination do
stub_request(:head, "https://eviltrout.com").to_return(doc_response)
end
it "escapes url" do
url = 'https://eviltrout.com?s=180&d=mm&r=g'
escaped_url = URI.escape(url)
stub_request(:head, escaped_url).to_return(doc_response)
expect(fd(url).resolve.to_s).to eq(escaped_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')