Skip to content

Commit

Permalink
[qtconsole] carriage-return action matches CR only, not CRLF
Browse files Browse the repository at this point in the history
CarriageReturn action introduced in ipython#1089 clears a line in the qtconsole, which means that CRLF line endings would replace whole lines with '\n'.

This changes the regex to only match `\r` not followed by `\n` preventing the CR action from firing on CRLF.

Test included

closes ipython#1111
  • Loading branch information
minrk committed Dec 9, 2011
1 parent 96e8539 commit 814d5b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion IPython/frontend/qt/console/ansi_code_processor.py
Expand Up @@ -38,7 +38,7 @@
OSC_SUBPATTERN = '\](.*?)[\x07\x1b]'
ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \
(CSI_SUBPATTERN, OSC_SUBPATTERN))
ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r)|(?:%s)' % ANSI_PATTERN)
ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r(?!\n))|(?:%s)' % ANSI_PATTERN)
SPECIAL_PATTERN = re.compile('([\f])')

#-----------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion IPython/frontend/qt/console/tests/test_ansi_code_processor.py
Expand Up @@ -105,12 +105,21 @@ def test_formfeed(self):
def test_carriage_return(self):
""" Are carriage return characters processed correctly?
"""
string = 'foo\rbar' # form feed
string = 'foo\rbar' # carriage return
self.assertEquals(list(self.processor.split_string(string)), ['foo', '', 'bar'])
self.assertEquals(len(self.processor.actions), 1)
action = self.processor.actions[0]
self.assertEquals(action.action, 'carriage-return')

def test_carriage_return_newline(self):
"""transform CRLF to LF"""
string = 'foo\rbar\r\ncat\r\n' # carriage return and newline
# only one CR action should occur, and '\r\n' should transform to '\n'
self.assertEquals(list(self.processor.split_string(string)), ['foo', '', 'bar\r\ncat\r\n'])
self.assertEquals(len(self.processor.actions), 1)
action = self.processor.actions[0]
self.assertEquals(action.action, 'carriage-return')

def test_beep(self):
""" Are beep characters processed correctly?
"""
Expand Down

0 comments on commit 814d5b9

Please sign in to comment.