Skip to content

Commit d95b522

Browse files
authored
Merge pull request #53 from jenner/parser-vtab-fix
Fix vertical tab handling in parser.
2 parents 1661f78 + a6a7262 commit d95b522

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

rtkit/parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
try:
22
from itertools import filterfalse as ifilterfalse
3+
from cStringIO import StringIO
34
except ImportError:
45
from itertools import ifilterfalse
6+
from io import StringIO
57
import re
68
from rtkit import comment
79

@@ -112,8 +114,11 @@ def build(cls, body):
112114
"""
113115
def build_section(section):
114116
logic_lines = []
115-
for line in filter(None, section.splitlines()):
116-
if cls.HEADER.match(line):
117+
for line in StringIO(section):
118+
# strip trailing newline
119+
if line and line[-1] == '\n':
120+
line = line.rstrip('\n')
121+
if not line or cls.HEADER.match(line):
117122
continue
118123
if line[0].isspace():
119124
logic_lines[-1] += '\n' + line.strip(' ')

rtkit/tests/parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ def test_parse_kw_syntax_err(self):
2929
'''
3030
parsed = RTParser.parse(body, RTParser.decode_comment)
3131
self.assertEqual(parsed, [[('queue', 'You may not create requests in that queue.')]])
32+
33+
def test_vertical_tab(self):
34+
body = '''RT/3.8.7 200 Ok
35+
Field: first line
36+
second\vline
37+
third line
38+
'''
39+
parsed = RTParser.parse(body, RTParser.decode)
40+
self.assertEqual(parsed, [[('Field', 'first line\nsecond\x0bline\nthird line')]])

0 commit comments

Comments
 (0)