Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitter emits extra space when emitting null values #46

Closed
ingydotnet opened this issue Dec 29, 2016 · 5 comments
Closed

Emitter emits extra space when emitting null values #46

ingydotnet opened this issue Dec 29, 2016 · 5 comments

Comments

@ingydotnet
Copy link
Member

If you look at
https://github.com/yaml/libyaml-test/blob/master/test/libyaml-emitter.skip#L4
you'll see that the emitter test skips 12 tests because libyaml emits an extra
space at the end of a line where an empty string is emitted for a null value.

Using underscore to show a space char, libyaml emits:

foo:_
bar:
-_

To emit this data:

{"foo":null,"bar":[null]}

This is obviously because libyaml emits a space right after - or : which is
right most of the time.

Depending on when the output buffer is actually flushed, we might be able to do
an easy fix of backing up before the space when we get to a null value. Need to
look at the code.

@david-a-wheeler
Copy link

Please don't create ending whitespace. Many projects' git repos or continuous integration (CI) process will automatically reject trailing whitespace. For example, the [CII best practices badge](https://github.com/linuxfoundation/cii-best-practices-badge] CI process run "git diff --check" to find any trailing whitespace & rejects commits that include them.

david-a-wheeler added a commit to coreinfrastructure/best-practices-badge that referenced this issue May 10, 2017
The "translation:sync" task syncs up the translations, but uses the usual
YAML writer, which writes out trailing whitespace.  It should not do that,
and the trailing whitespace causes later failures in testing.
Problem already reported:
- translation/rails#13
- yaml/libyaml#46

For now, we'll run this enhancement to solve the problem.

Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
@juanibiapina
Copy link

juanibiapina commented Jan 23, 2020

This looks like a long standing bug. The rails solution simply removes trailing whitespace after generating the file. Why not fix it directly here?

perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
See issue yaml#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
perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
See issue yaml#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
perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
See issue yaml#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
perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
See issue yaml#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
@perlpunk
Copy link
Member

I created a PR for fixing this: #186

It was easier than I thought, because the emitter does not output the space directly after the : and -.

perlpunk added a commit to perlpunk/libyaml that referenced this issue May 31, 2020
See issue yaml#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
perlpunk added a commit to perlpunk/libyaml that referenced this issue Jun 1, 2020
See issue yaml#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
perlpunk added a commit that referenced this issue Jun 1, 2020
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
@perlpunk
Copy link
Member

perlpunk commented Jun 1, 2020

Released 0.2.5!

@perlpunk perlpunk closed this as completed Jun 1, 2020
@david-a-wheeler
Copy link

Thank you!

richardlarocque added a commit to richardlarocque/camcorder that referenced this issue May 24, 2024
The folks behind libyaml decided to change it so it was less likely to
emit trailing whitespace.  That's good for them, but bad for us.  We've
been using MD5 hashes of those YAML dumps for our recordings and now
those MD5 hash values are different.

Eventually we'll want to settle towards the new behavior.  But we can't
just go updating the hashes; some dev machines / build bots / whatever
still have the old libyaml and would be confused by the new hashes.

This ugly hack is good enough to keep tests passing in either libyaml
version, for now.  Hopefully it'll get us over the hump and we can
remove it and re-record the tests alter.

I think this is the PR that changed the behavior:
yaml/libyaml#46
richardlarocque added a commit to getoutreach/camcorder that referenced this issue May 28, 2024
[STAR-2408](https://outreach-io.atlassian.net/browse/STAR-2408)

The folks behind libyaml decided to change it so it was less likely to
emit trailing whitespace.  That's good for them, but bad for us.  We've
been using MD5 hashes of those YAML dumps for our recordings and now
those MD5 hash values are different.

Eventually we'll want to settle towards the new behavior.  But we can't
just go updating the hashes; some dev machines / build bots / whatever
still have the old libyaml and would be confused by the new hashes.

This ugly hack is good enough to keep tests passing in either libyaml
version, for now.  Hopefully it'll get us over the hump and we can
remove it and re-record the tests alter.

I think this is the PR that changed the behavior:
yaml/libyaml#46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants