Skip to content

bpo-30119: Fix ftplib to handle the ftp user's commands. #1214

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

Merged
merged 1 commit into from
Jul 22, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def sanitize(self, s):

# Internal: send one line to the server, appending CRLF
def putline(self, line):
if '\r' in line or '\n' in line:
raise ValueError('an illegal newline character should not be contained')
line = line + CRLF
if self.debugging > 1:
print('*put*', self.sanitize(line))
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ def test_sanitize(self):
self.assertEqual(self.client.sanitize('PASS 12345'), repr('PASS *****'))

def test_exceptions(self):
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r\n0')
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\n0')
self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r0')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 400')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 499')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 500')
Expand All @@ -493,7 +496,8 @@ def test_exceptions(self):

def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
ftplib.error_proto, ftplib.Error, OSError, EOFError)
ftplib.error_proto, ftplib.Error, OSError,
EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ Extension Modules
Library
-------

- bpo-30119: ftplib.FTP.putline() now throws ValueError on commands that contains
CR or LF. Patch by Dong-hee Na.

- bpo-30879: os.listdir() and os.scandir() now emit bytes names when called
with bytes-like argument.

Expand Down