diff options
author | Tina Müller <cpan2@tinita.de> | 2020-03-23 17:29:27 +0100 |
---|---|---|
committer | Tina Müller (tinita) <cpan2@tinita.de> | 2020-03-26 22:28:39 +0100 |
commit | 9afa10a8b04e8fb2883b11e7f32f2da1e2ced0d2 (patch) | |
tree | 1490b47b98f2f9d55792fd9179734f3d00545063 /src | |
parent | 21429b031f72f12fa8a8f9d2aadb38aba994ac94 (diff) | |
download | libyaml-git-9afa10a8b04e8fb2883b11e7f32f2da1e2ced0d2.tar.gz |
Always output document end before directive (YAML 1.2 compatibility)
In YAML 1.1, the document end marker `...` is optional even if the next document starts with a directive:
https://github.com/yaml/pyyaml/blob/master/tests/data/spec-07-09.canonical
```
%YAML 1.1
---
!!str "foo"
%YAML 1.1
---
!!str "bar"
%YAML 1.1
---
!!str "baz"
```
It is only required if the scalar is "open ended", for example for plain scalars.
In YAML 1.2 the `...` marker is always required before a directive.
My suggestion would be to make the output 1.2 compatible. It will still be 1.1 compatible, so that shouldn't be a problem.
I believe this will also make it easier to fix #123 which was introduced with the last fixes regarding `open_ended`. I think I can make a fix for this soon after this issue is fixed.
Fixing #123 without this would be a bit more complicated.
If we do this, we also need to adjust PyYAML to behave the same.
Related issues/commits:
- https://github.com/yaml/libyaml/issues/60
- https://github.com/yaml/libyaml/pull/122
- 56400d9, 8ee83c0, 56f4b17
Diffstat (limited to 'src')
-rw-r--r-- | src/emitter.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/emitter.c b/src/emitter.c index f26c53b..21ef1b2 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -594,6 +594,7 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter, { if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) return 0; + emitter->open_ended = 0; if (!yaml_emitter_write_indent(emitter)) return 0; } @@ -644,6 +645,7 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter, emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE; + emitter->open_ended = 0; return 1; } @@ -691,6 +693,7 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter, if (!event->data.document_end.implicit) { if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) return 0; + emitter->open_ended = 0; if (!yaml_emitter_write_indent(emitter)) return 0; } @@ -1796,7 +1799,6 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter, emitter->whitespace = is_whitespace; emitter->indention = (emitter->indention && is_indention); - emitter->open_ended = 0; return 1; } @@ -1939,10 +1941,6 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, emitter->whitespace = 0; emitter->indention = 0; - if (emitter->root_context) - { - emitter->open_ended = 1; - } return 1; } |