From acd2b8d43b5ebec7ffd364b6f335427041a0b98d Mon Sep 17 00:00:00 2001 From: NewUserHa <32261870+NewUserHa@users.noreply.github.com> Date: Thu, 22 Feb 2018 06:37:26 +0800 Subject: [PATCH] [MRG+1] Fix part of issue #3128 - None should not be a valid type for 'url' in Response.follow (#3131) * fix one issue of issue#3128 because @kmike posted: 'If url is '', Scrapy should follow the same page, this is an intended behavior.' * fix one issue of issue#3128 because @kmike posted: 'If url is '', Scrapy should follow the same page, this is an intended behavior.' --- scrapy/http/response/__init__.py | 2 ++ tests/test_http_response.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/scrapy/http/response/__init__.py b/scrapy/http/response/__init__.py index 434d87eab..1974259b5 100644 --- a/scrapy/http/response/__init__.py +++ b/scrapy/http/response/__init__.py @@ -120,6 +120,8 @@ class Response(object_ref): """ if isinstance(url, Link): url = url.url + elif url is None: + raise ValueError("url can't be None") url = self.urljoin(url) return Request(url, callback, method=method, diff --git a/tests/test_http_response.py b/tests/test_http_response.py index b228344b5..820758dc9 100644 --- a/tests/test_http_response.py +++ b/tests/test_http_response.py @@ -155,6 +155,10 @@ class BaseResponseTest(unittest.TestCase): self._assert_followed_url(Link('http://example.com/foo'), 'http://example.com/foo') + def test_follow_None_url(self): + r = self.response_class("http://example.com") + self.assertRaises(ValueError, r.follow, None) + def test_follow_whitespace_url(self): self._assert_followed_url('foo ', 'http://example.com/foo%20')