Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Fix ShellTest.test_local_file on Windows

Adrián Chaves2f510fd47d8d
diff --git a/scrapy/utils/url.py b/scrapy/utils/url.py
index c9abb12d5..c29ed4461 100644
--- a/scrapy/utils/url.py
+++ b/scrapy/utils/url.py
@@ -85,11 +85,9 @@ def add_http_if_no_scheme(url):
def guess_scheme(url):
- """Add an URL scheme if missing: file:// for filepath-like input or http:// otherwise."""
- parts = urlparse(url)
- if parts.scheme:
- return url
- # Note: this does not match Windows filepath
+ """Add an URL scheme if missing: file:// for filepath-like input or
+ http:// otherwise."""
+ # POSIX path
if re.match(r'''^ # start with...
(
\. # ...a single dot,
@@ -99,7 +97,10 @@ def guess_scheme(url):
)? # optional match of ".", ".." or ".blabla"
/ # at least one "/" for a file path,
. # and something after the "/"
- ''', parts.path, flags=re.VERBOSE):
+ ''', url, flags=re.VERBOSE):
+ return any_to_uri(url)
+ # Windows drive-letter path
+ elif re.match(r'''^[a-z]:\\''', url, flags=re.IGNORECASE):
return any_to_uri(url)
else:
return add_http_if_no_scheme(url)
diff --git a/tests/test_command_shell.py b/tests/test_command_shell.py
index d664b6ade..acf8e9f71 100644
--- a/tests/test_command_shell.py
+++ b/tests/test_command_shell.py
@@ -94,7 +94,7 @@ class ShellTest(ProcessTest, SiteTest, unittest.TestCase):
@defer.inlineCallbacks
def test_local_file(self):
- filepath = join(tests_datadir, 'test_site/index.html')
+ filepath = join(tests_datadir, 'test_site', 'index.html')
_, out, _ = yield self.execute([filepath, '-c', 'item'])
assert b'{}' in out