From 814d5b9f9564b3f5a2a5428c54736240fbe5be0e Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 7 Dec 2011 13:21:49 -0800 Subject: [PATCH] [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 --- IPython/frontend/qt/console/ansi_code_processor.py | 2 +- .../qt/console/tests/test_ansi_code_processor.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/qt/console/ansi_code_processor.py b/IPython/frontend/qt/console/ansi_code_processor.py index f027ccf31ae..76019b39476 100644 --- a/IPython/frontend/qt/console/ansi_code_processor.py +++ b/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])') #----------------------------------------------------------------------------- diff --git a/IPython/frontend/qt/console/tests/test_ansi_code_processor.py b/IPython/frontend/qt/console/tests/test_ansi_code_processor.py index bbffd85aed7..30698b12032 100644 --- a/IPython/frontend/qt/console/tests/test_ansi_code_processor.py +++ b/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? """