aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-08-01 03:31:09 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-08-01 03:31:09 +0000
commit7905d61b2cff841dfdc79bfca92ce23c717ab384 (patch)
treefe25e85b5b72595a14145fc4c6007a8f61131529 /Lib/cmd.py
parentFix build on VS8. (diff)
downloadcpython-7905d61b2cff841dfdc79bfca92ce23c717ab384.tar.gz
cpython-7905d61b2cff841dfdc79bfca92ce23c717ab384.tar.bz2
cpython-7905d61b2cff841dfdc79bfca92ce23c717ab384.zip
#8620: Cmd no longer truncates last character if stdin ends without newline
Cmd used to blindly chop off the last character of every input line. If the input reached EOF and there was no final new line, it would truncate the last character of the last command. This fix instead strips trailing \r\n from the input lines. While this is a small behavior change, it should not break any working code, since feeding a '\r\n' terminated file to Cmd would previously leave the \r's on the lines, resulting in failed command execution. I wrote the unit test in preparation for a PyOhio TeachMe session run by Catherine Devlin, and we can thank Catherine and the PyOhio session attendees for the fix. I've added Catherine to the Acks file for organizing and leading the TeachMe session, out of which we will hopefully get some new contributors.
Diffstat (limited to 'Lib/cmd.py')
-rw-r--r--Lib/cmd.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/cmd.py b/Lib/cmd.py
index c791d6b256b..85282f89a6b 100644
--- a/Lib/cmd.py
+++ b/Lib/cmd.py
@@ -133,7 +133,7 @@ class Cmd:
if not len(line):
line = 'EOF'
else:
- line = line[:-1] # chop \n
+ line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)