Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider about: URLs invalid #4835

Merged
merged 1 commit into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion scrapy/http/request/__init__.py
Expand Up @@ -65,7 +65,11 @@ def _set_url(self, url):
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'))
Expand Down
9 changes: 9 additions & 0 deletions tests/test_http_request.py
Expand Up @@ -43,6 +43,15 @@ def test_init(self):
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/')
Expand Down