mirror of https://github.com/scrapy/scrapy.git
fix: Adding protocol_relative_pattern to reject another pattern for invalid URLs
This commit is contained in:
parent
0a152764fb
commit
f38c2afe91
|
|
@ -101,13 +101,14 @@ class OffsiteMiddleware:
|
|||
misconfigured domains.
|
||||
"""
|
||||
url_pattern = re.compile(r"^https?://.*$")
|
||||
protocol_relative_pattern = re.compile(r"^//")
|
||||
port_pattern = re.compile(r":\d+$")
|
||||
valid_domains: list[str] = []
|
||||
|
||||
for domain in domains_list:
|
||||
if domain is None:
|
||||
raise ValueError(f"{domains_type} contains empty value.")
|
||||
if url_pattern.match(domain):
|
||||
if url_pattern.match(domain) or protocol_relative_pattern.match(domain):
|
||||
raise ValueError(
|
||||
f"{domains_type} accepts only domains, not URLs. "
|
||||
f"Got URL entry {domain} in {domains_type}."
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ def test_process_request_no_allowed_domains(value):
|
|||
[
|
||||
["a.example", None],
|
||||
["a.example", "http://b.example"],
|
||||
["a.example", "//c.example"],
|
||||
["a.example", "c.example:8080"],
|
||||
],
|
||||
)
|
||||
|
|
@ -233,6 +234,7 @@ def test_request_scheduled_no_allowed_domains(value):
|
|||
[
|
||||
["a.example", None],
|
||||
["a.example", "http://b.example"],
|
||||
["a.example", "//c.example"],
|
||||
["a.example", "c.example:8080"],
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue