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