Skip to content

Commit

Permalink
Fix vertical tab handling in parser.
Browse files Browse the repository at this point in the history
Python's string.splitlines() also splits on vertical tabs, which
can be used as content in tickets.

Resolves z4r#52
  • Loading branch information
jenner committed Jun 14, 2017
1 parent 1661f78 commit a6a7262
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rtkit/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
try:
from itertools import filterfalse as ifilterfalse
from cStringIO import StringIO
except ImportError:
from itertools import ifilterfalse
from io import StringIO
import re
from rtkit import comment

Expand Down Expand Up @@ -112,8 +114,11 @@ def build(cls, body):
"""
def build_section(section):
logic_lines = []
for line in filter(None, section.splitlines()):
if cls.HEADER.match(line):
for line in StringIO(section):
# strip trailing newline
if line and line[-1] == '\n':
line = line.rstrip('\n')
if not line or cls.HEADER.match(line):
continue
if line[0].isspace():
logic_lines[-1] += '\n' + line.strip(' ')
Expand Down
9 changes: 9 additions & 0 deletions rtkit/tests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ def test_parse_kw_syntax_err(self):
'''
parsed = RTParser.parse(body, RTParser.decode_comment)
self.assertEqual(parsed, [[('queue', 'You may not create requests in that queue.')]])

def test_vertical_tab(self):
body = '''RT/3.8.7 200 Ok
Field: first line
second\vline
third line
'''
parsed = RTParser.parse(body, RTParser.decode)
self.assertEqual(parsed, [[('Field', 'first line\nsecond\x0bline\nthird line')]])

0 comments on commit a6a7262

Please sign in to comment.