1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-03-14 02:39:27 +00:00

Do not consider about: URLs invalid

This commit is contained in:
Adrián Chaves 2020-10-06 19:13:29 +02:00
parent b1255b016a
commit e40788153c
2 changed files with 14 additions and 1 deletions

View File

@ -65,7 +65,11 @@ class Request(object_ref):
s = safe_url_string(url, self.encoding)
self._url = escape_ajax(s)
if ('://' not in self._url) and (not self._url.startswith('data:')):
if (
'://' not in self._url
and not self._url.startswith('about:')
and not self._url.startswith('data:')
):
raise ValueError(f'Missing scheme in request url: {self._url}')
url = property(_get_url, obsolete_setter(_set_url, 'url'))

View File

@ -43,6 +43,15 @@ class RequestTest(unittest.TestCase):
assert r.headers is not headers
self.assertEqual(r.headers[b"caca"], b"coco")
def test_url_scheme(self):
# This test passes by not raising any (ValueError) exception
self.request_class('http://example.org')
self.request_class('https://example.org')
self.request_class('s3://example.org')
self.request_class('ftp://example.org')
self.request_class('about:config')
self.request_class('data:,Hello%2C%20World!')
def test_url_no_scheme(self):
self.assertRaises(ValueError, self.request_class, 'foo')
self.assertRaises(ValueError, self.request_class, '/foo/')