summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2019-11-26 08:00:33 +0100
committerAnthon van der Neut <anthon@mnt.org>2019-11-26 08:00:33 +0100
commit245f5a1667033634d4069ee48b7d6915489148fd (patch)
treed52fb0f23d3e3504d6d2df4256a7536faac5d6d1
parentcc39b48f95d59bc09cea2470d1d69431dee43725 (diff)
downloadruamel.yaml-245f5a1667033634d4069ee48b7d6915489148fd.tar.gz
empty string mapping key preservation
Would convert to explicit key (? '')
-rw-r--r--README.rst4
-rw-r--r--emitter.py3
2 files changed, 6 insertions, 1 deletions
diff --git a/README.rst b/README.rst
index 4bbe9c0..58403df 100644
--- a/README.rst
+++ b/README.rst
@@ -54,6 +54,10 @@ ChangeLog
.. should insert NEXT: at the beginning of line for next key (with empty line)
+NEXT:
+ - fix empty string mapping key roundtripping with preservation of quotes as `? ''`
+ (reported via email by Tomer Aharoni).
+
0.16.5 (2019-08-18):
- allow for ``YAML(typ=['unsafe', 'pytypes'])``
diff --git a/emitter.py b/emitter.py
index 73fbe05..41dc3e8 100644
--- a/emitter.py
+++ b/emitter.py
@@ -769,7 +769,8 @@ class Emitter(object):
or (isinstance(self.event, MappingStartEvent) and self.event.flow_style is True)
or (
isinstance(self.event, ScalarEvent)
- and not self.analysis.empty
+ # if there is an explicit style for an empty string, it is a simple key
+ and not (self.analysis.empty and self.style and self.style not in '\'"')
and not self.analysis.multiline
)
or self.check_empty_sequence()