Skip to content

Commit

Permalink
Fix parsing of multi-line strings in YAML blocks (#112)
Browse files Browse the repository at this point in the history
Closes #111.
  • Loading branch information
dato committed May 10, 2020
1 parent 015c21c commit 0aedb99
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -3,6 +3,7 @@ tappy was originally created by Matt Layman.
Contributors
------------

* Adeodato Simó
* Andrew McNamara
* Chris Clarke
* Erik Cederstrand
Expand Down
1 change: 1 addition & 0 deletions docs/releases.rst
Expand Up @@ -5,6 +5,7 @@ Version 3.1, To Be Released
---------------------------

* Add support for Python 3.8.
* Fix parsing of multi-line strings in YAML blocks (#111)

Version 3.0, Released January 10, 2020
--------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion tap/parser.py
Expand Up @@ -181,7 +181,8 @@ def _extract_yaml_block(self, indent, fh):
try:
next(fh)
while indent_match.match(fh.peek()):
raw_yaml.append(next(fh).replace(indent, "", 1))
yaml_line = next(fh).replace(indent, "", 1)
raw_yaml.append(yaml_line.rstrip("\n"))
# check for the end and stop adding yaml if encountered
if self.yaml_block_end.match(fh.peek()):
next(fh)
Expand Down
14 changes: 10 additions & 4 deletions tap/tests/test_parser.py
Expand Up @@ -348,7 +348,12 @@ def test_parses_yaml_more_complex(self):
got:
- foo
expect:
- bar"""
- bar
output: |-
a multiline string
must be handled properly
even with | pipes
| here > and: there"""
)
parser = Parser()
lines = []
Expand All @@ -358,20 +363,21 @@ def test_parses_yaml_more_complex(self):

if have_yaml:
converted_yaml = yaml.safe_load(
u"""
u'''
message: test
severity: fail
data:
got:
- foo
expect:
- bar"""
- bar
output: "a multiline string\\nmust be handled properly\\neven with | pipes\\n| here > and: there"'''
)
self.assertEqual(3, len(lines))
self.assertEqual(13, lines[0].version)
self.assertEqual(converted_yaml, lines[2].yaml_block)
else:
self.assertEqual(11, len(lines))
self.assertEqual(16, len(lines))
self.assertEqual(13, lines[0].version)
for l in list(range(3, 11)):
self.assertEqual("unknown", lines[l].category)
Expand Down

0 comments on commit 0aedb99

Please sign in to comment.