[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.'
This commit is contained in:
NewUserHa 2018-02-22 06:37:26 +08:00 committed by Mikhail Korobov
parent 426da0ed07
commit acd2b8d43b
2 changed files with 6 additions and 0 deletions

View File

@ -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,

View File

@ -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')