mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 04:04:21 +00:00
Merge pull request #1254 from scrapy/bugfix-1232
[MRG +1] Unquote request path before passing to FTPClient, it already escape paths
This commit is contained in:
commit
ea4b175c2d
@ -30,7 +30,7 @@ In case of status 200 request, response.headers will come with two keys:
|
||||
|
||||
import re
|
||||
from io import BytesIO
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from six.moves.urllib.parse import urlparse, unquote
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.protocols.ftp import FTPClient, CommandFailed
|
||||
@ -73,7 +73,7 @@ class FTPDownloadHandler(object):
|
||||
request.meta["ftp_password"],
|
||||
passive=request.meta.get("ftp_passive", 1))
|
||||
return creator.connectTCP(parsed_url.hostname, parsed_url.port or 21).addCallback(self.gotClient,
|
||||
request, parsed_url.path)
|
||||
request, unquote(parsed_url.path))
|
||||
|
||||
def gotClient(self, client, request, filepath):
|
||||
self.client = client
|
||||
|
@ -511,7 +511,9 @@ class FTPTestCase(unittest.TestCase):
|
||||
os.mkdir(self.directory)
|
||||
userdir = os.path.join(self.directory, self.username)
|
||||
os.mkdir(userdir)
|
||||
FilePath(userdir).child('file.txt').setContent("I have the power!")
|
||||
fp = FilePath(userdir)
|
||||
fp.child('file.txt').setContent("I have the power!")
|
||||
fp.child('file with spaces.txt').setContent("Moooooooooo power!")
|
||||
|
||||
# setup server
|
||||
realm = FTPRealm(anonymousRoot=self.directory, userHome=self.directory)
|
||||
@ -547,6 +549,19 @@ class FTPTestCase(unittest.TestCase):
|
||||
self.assertEqual(r.headers, {'Local Filename': [''], 'Size': ['17']})
|
||||
return self._add_test_callbacks(d, _test)
|
||||
|
||||
def test_ftp_download_path_with_spaces(self):
|
||||
request = Request(
|
||||
url="ftp://127.0.0.1:%s/file with spaces.txt" % self.portNum,
|
||||
meta={"ftp_user": self.username, "ftp_password": self.password}
|
||||
)
|
||||
d = self.download_handler.download_request(request, None)
|
||||
|
||||
def _test(r):
|
||||
self.assertEqual(r.status, 200)
|
||||
self.assertEqual(r.body, 'Moooooooooo power!')
|
||||
self.assertEqual(r.headers, {'Local Filename': [''], 'Size': ['18']})
|
||||
return self._add_test_callbacks(d, _test)
|
||||
|
||||
def test_ftp_download_notexist(self):
|
||||
request = Request(url="ftp://127.0.0.1:%s/notexist.txt" % self.portNum,
|
||||
meta={"ftp_user": self.username, "ftp_password": self.password})
|
||||
|
Loading…
x
Reference in New Issue
Block a user