Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[qtconsole] carriage-return action matches CR only, not CRLF

CarriageReturn action introduced in #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 #1111
  • Loading branch information...
commit 814d5b9f9564b3f5a2a5428c54736240fbe5be0e 1 parent 96e8539
@minrk authored
View
2  IPython/frontend/qt/console/ansi_code_processor.py
@@ -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])')
#-----------------------------------------------------------------------------
View
11 IPython/frontend/qt/console/tests/test_ansi_code_processor.py
@@ -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?
"""
Please sign in to comment.
Something went wrong with that request. Please try again.