Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

protect CRLF from carriage-return action #1118

Merged
merged 1 commit into from Dec 9, 2011
Jump to file or symbol
Failed to load files and symbols.
+11 −2
Split
@@ -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])')
#-----------------------------------------------------------------------------
@@ -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?
"""