From abccdd1365296e93aedfb1150f16623dbf63d257 Mon Sep 17 00:00:00 2001 From: Victor Maslov Date: Wed, 25 Apr 2018 22:48:36 +0300 Subject: [PATCH] unescaped space symbol in redirect caused URI::InvalidURIError --- lib/fastimage.rb | 2 +- test/test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fastimage.rb b/lib/fastimage.rb index 522f5d8..6c23e80 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -250,7 +250,7 @@ class FastImage if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4 @redirect_count += 1 begin - @parsed_uri = URI.join(@parsed_uri, res['Location']) + @parsed_uri = URI.join(@parsed_uri, URI.escape(res['Location'])) rescue URI::InvalidURIError else fetch_using_http_from_parsed_uri diff --git a/test/test.rb b/test/test.rb index 68b0b19..6964abd 100644 --- a/test/test.rb +++ b/test/test.rb @@ -248,8 +248,8 @@ class FastImageTest < Test::Unit::TestCase end def test_should_handle_permanent_redirect_with_complex_relative_url - register_redirect(TestUrl, "/photo.gne?rb=1&short=Vv4Und") - register_redirect("#{TestUrl}photo.gne?rb=1&short=Vv4Und", "/" + GoodFixtures.keys.first) + register_redirect(TestUrl, "/pho to.gne?rb=1&short=Vv4Und") + register_redirect("#{TestUrl}pho%20to.gne?rb=1&short=Vv4Und", "/" + GoodFixtures.keys.first) assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(TestUrl, :raise_on_failure=>true) end