Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

protect CRLF from carriage-return action #1118

Merged
merged 1 commit into from

1 participant

@minrk
Owner

Carriage return action introduced in PR #1089 clears a line in the qtconsole, which means that CRLF line endings would replace whole lines with '\n', thus hiding the output of ls and ~all system calls.

This changes the behavior to only act on CR if it is not followed by LF.

Test included.

closes #1111

@minrk minrk [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
814d5b9
@minrk
Owner

updated to just change the regex to match \r not followed by \n

@minrk minrk merged commit 814d5b9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2011
  1. @minrk

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

    minrk authored
    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
This page is out of date. Refresh to see the latest.
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?
"""
Something went wrong with that request. Please try again.