diff options
author | Tina Müller (tinita) <cpan2@tinita.de> | 2020-06-01 16:41:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 16:41:23 +0200 |
commit | 7eb01976a05d9a43f3d3d7ffe870a1c4a0f1090d (patch) | |
tree | 49e4e1d1cd0f15494949c4011fb219bfeb84acb8 | |
parent | 6e2fa9786ae20b670e77a72f1271d7574bc89f0f (diff) | |
download | libyaml-git-7eb01976a05d9a43f3d3d7ffe870a1c4a0f1090d.tar.gz |
Emitter: Don't output trailing space for empty scalar nodes (#186)
See issue #46
Passing emitter tests:
* 2XXW: Spec Example 2.25. Unordered Sets
* 5WE3: Spec Example 8.17. Explicit Block Mapping Entries
* 6KGN: Anchor for empty node
* 6XDY: Two document start markers
* 7W2P: Block Mapping with Missing Values
* 8KB6: Multiline plain flow mapping key without value
* 9BXH: Multiline doublequoted flow mapping key without value
* C2DT: Spec Example 7.18. Flow Mapping Adjacent Values
* JTV5: Block Mapping with Multiline Scalars
* KK5P: Various combinations of explicit block mappings
* LE5A: Spec Example 7.24. Flow Nodes
* UT92: Spec Example 9.4. Explicit Documents
* W42U: Spec Example 8.15. Block Sequence Entry Types
* W4TN: Spec Example 9.5. Directives Documents
* ZWK4: Key with anchor after missing explicit mapping value
-rw-r--r-- | src/emitter.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/emitter.c b/src/emitter.c index 656b3ad..609b28a 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -1925,7 +1925,17 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, STRING_ASSIGN(string, value, length); - if (!emitter->whitespace) { + /** + * Avoid trailing spaces for empty values in block mode. + * In flow mode, we still want the space to prevent ambiguous things + * like {a:}. + * Currently, the emitter forbids any plain empty scalar in flow mode + * (e.g. it outputs {a: ''} instead), so emitter->flow_level will + * never be true here. + * But if the emitter is ever changed to allow emitting empty values, + * the check for flow_level is already here. + */ + if (!emitter->whitespace && (length || emitter->flow_level)) { if (!PUT(emitter, ' ')) return 0; } |