Skip to content
This repository

protect CRLF from carriage-return action #1118

Merged
merged 1 commit into from over 2 years ago

1 participant

Min RK
Min RK
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

Min RK [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
Min RK
Owner

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

Min RK minrk merged commit 814d5b9 into from December 09, 2011
Min RK minrk closed this December 09, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 09, 2011
Min RK [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
This page is out of date. Refresh to see the latest.
2  IPython/frontend/qt/console/ansi_code_processor.py
@@ -38,7 +38,7 @@
38 38
 OSC_SUBPATTERN = '\](.*?)[\x07\x1b]'
39 39
 ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \
40 40
                 (CSI_SUBPATTERN, OSC_SUBPATTERN))
41  
-ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r)|(?:%s)' % ANSI_PATTERN)
  41
+ANSI_OR_SPECIAL_PATTERN = re.compile('(\b|\r(?!\n))|(?:%s)' % ANSI_PATTERN)
42 42
 SPECIAL_PATTERN = re.compile('([\f])')
43 43
 
44 44
 #-----------------------------------------------------------------------------
11  IPython/frontend/qt/console/tests/test_ansi_code_processor.py
@@ -105,12 +105,21 @@ def test_formfeed(self):
105 105
     def test_carriage_return(self):
106 106
         """ Are carriage return characters processed correctly?
107 107
         """
108  
-        string = 'foo\rbar' # form feed
  108
+        string = 'foo\rbar' # carriage return
109 109
         self.assertEquals(list(self.processor.split_string(string)), ['foo', '', 'bar'])
110 110
         self.assertEquals(len(self.processor.actions), 1)
111 111
         action = self.processor.actions[0]
112 112
         self.assertEquals(action.action, 'carriage-return')
113 113
 
  114
+    def test_carriage_return_newline(self):
  115
+        """transform CRLF to LF"""
  116
+        string = 'foo\rbar\r\ncat\r\n' # carriage return and newline
  117
+        # only one CR action should occur, and '\r\n' should transform to '\n'
  118
+        self.assertEquals(list(self.processor.split_string(string)), ['foo', '', 'bar\r\ncat\r\n'])
  119
+        self.assertEquals(len(self.processor.actions), 1)
  120
+        action = self.processor.actions[0]
  121
+        self.assertEquals(action.action, 'carriage-return')
  122
+
114 123
     def test_beep(self):
115 124
         """ Are beep characters processed correctly?
116 125
         """
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.