Fix marshaling of leading and trailing whitespace#792
Fix marshaling of leading and trailing whitespace#792quentinmit wants to merge 3 commits intogoccy:masterfrom
Conversation
This ensures that we can successfully marshal/unmarshal the value. One test now fails. I marked it as a failing test instead of trying to figure out how to fix it.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #792 +/- ##
==========================================
+ Coverage 77.97% 78.00% +0.03%
==========================================
Files 22 22
Lines 8108 8108
==========================================
+ Hits 6322 6325 +3
+ Misses 1370 1367 -3
Partials 416 416 🚀 New features to boost your workflow:
|
| "invalid-comment-after-end-of-flow-sequence", | ||
| "invalid-comma-in-tag", | ||
| "plain-dashes-in-flow-sequence", | ||
| "spec-example-8-17-explicit-block-mapping-entries", |
There was a problem hiding this comment.
Why did this test case start to fail?
There was a problem hiding this comment.
It did not start to fail; it was always broken, but because the test code never checks how the data remarshals (e.g. by checking OutYAML), we didn't know that it was broken.
The initial unmarshal (still) works, but it cannot be re-marshaled correctly:
yaml_test_suite_test.go:132: failed to round-trip value:
[yaml]
|
block key:
- one
- two
explicit key: null
[err]
[3:1] value is not allowed in this context
1 | |
2 | block key:
> 3 | - one
^
4 | - two
5 | explicit key: null
The original test input is:
explicit key:
? |
block key
: - one
- twoWe were and are correctly unmarshaling that to
{
"explicit key": null,
"block key\n": [
"one",
"two"
]
}but when we try to remarshal that, we generate
|
block key:
- one
- two
explicit key: nullwithout a ? before |\nblock key, which is invalid YAML.
This is a pre-existing bug and this PR does not cause or change it.
|
@goccy can we somehow merge is faster? any changes needed? |
Before submitting your PR, please confirm the following.
Current go-yaml will marshal
map[string]string{"a": "\tvalue"}as"a: \tvalue"(that is, a literal tab character). Unmarshaling that producesmap[string]string{"a": "value"}instead of the original map.In addition to fixing leading tabs and leading newlines, I also changed
TestYAMLTestSuiteto round-trip every value to make sure that they can be properly marshaled and unmarshaled without changing the value. This uncovered several broken test cases. All but one are fixed by this PR, since that last one doesn't (primarily, at least) involve whitespace.