From 5a9c5c0e8a9cf9ae7b982a1cc6963230b46c65ab Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Sun, 30 Sep 2012 17:47:17 -0300 Subject: [PATCH] Some bad sites gives in location header URL without proper encoding fixed with URI.encode --- lib/open-uri.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 7f2a056370d47a..7fb06114d5fb61 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -341,7 +341,9 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc: Net::HTTPSeeOther, # 303 Net::HTTPTemporaryRedirect # 307 begin - loc_uri = URI.parse(resp['location']) + # Some bad formed sites responds location with unescaped special chars. + # Just a new URI.encode solve this. + loc_uri = URI.parse(URI.encode(resp['location'])) rescue URI::InvalidURIError raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io) end