summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-16 18:23:25 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-16 18:23:25 +0100
commitf66a7feafc361bf830b5179578e1ecf00497d8f5 (patch)
tree6bfa401134c23e01b3e6cd674a9fcd5118c3cd1f
parent64ecb99083e3c81c13dec7d63314c877c72aef98 (diff)
downloadruamel.yaml-f66a7feafc361bf830b5179578e1ecf00497d8f5.tar.gz
Fix extra trailing line break with `|-` block literals
The Emitter.write_literal() function will write a line break after a block literal value if the block literal didn't end with a line break. The Scanner.scan_block_scalar() function was keeping track of all newlines that followed block literals, but when `|-` is used it this was one too many. The code is changed slightly to avoid a confusing `if chomping is not False` statement.
-rw-r--r--py/scanner.py6
-rw-r--r--test/test_string.py3
2 files changed, 3 insertions, 6 deletions
diff --git a/py/scanner.py b/py/scanner.py
index b497c4b..e3f0548 100644
--- a/py/scanner.py
+++ b/py/scanner.py
@@ -1068,13 +1068,11 @@ class Scanner(object):
# Process trailing line breaks. The 'chomping' setting determines
# whether they are included in the value.
comment = []
- if chomping is not False:
+ if chomping in [None, True]:
chunks.append(line_break)
- else:
- comment.append(line_break)
if chomping is True:
chunks.extend(breaks)
- else:
+ elif chomping in [None, False]:
comment.extend(breaks)
# We are done.
diff --git a/test/test_string.py b/test/test_string.py
index eb2e95c..8c08e7d 100644
--- a/test/test_string.py
+++ b/test/test_string.py
@@ -46,8 +46,7 @@ class TestYAML:
def
"""
- o = dedent(s).rstrip() + '\n'
- round_trip(s, outp=o, intermediate=dict(a='abc\ndef'))
+ round_trip(s, intermediate=dict(a='abc\ndef'))
def test_preserve_string_keep(self):
# with pytest.raises(AssertionError) as excinfo: