From 89f7a63db46f5821c629fa55dc45ade148b0e366 Mon Sep 17 00:00:00 2001 From: knu Date: Mon, 9 Feb 2009 03:16:49 +0000 Subject: r22165@crimson: knu | 2009-02-09 11:55:30 +0900 (OpenURI.open_http): rescue URI::InvalidURIError by URI.parse for location URI. (r15406) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@22158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 2 ++ lib/open-uri.rb | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index db17a8d859..7ab59950fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ Mon Feb 9 11:50:02 2009 Akinori MUSHA (OpenURI::Buffer): use Meta ===. [ruby-core:14295] (r14609) (OpenURI::Meta#content_type_parse): fix tests. [ruby-dev:33336] (r15200) + (OpenURI.open_http): rescue URI::InvalidURIError by URI.parse + for location URI. (r15406) Mon Feb 9 01:21:16 2009 Tanaka Akira diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 69232bf366..3132cd5593 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -327,7 +327,12 @@ module OpenURI Net::HTTPFound, # 302 Net::HTTPSeeOther, # 303 Net::HTTPTemporaryRedirect # 307 - throw :open_uri_redirect, URI.parse(resp['location']) + begin + loc_uri = URI.parse(resp['location']) + rescue URI::InvalidURIError + raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io) + end + throw :open_uri_redirect, loc_uri else raise OpenURI::HTTPError.new(io.status.join(' '), io) end -- cgit v1.2.3