summaryrefslogtreecommitdiff
path: root/src/emitter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emitter.c')
-rw-r--r--src/emitter.c12
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;
}