Repository navigation
End block scalars at document markers - #495
chinmayajha wants to merge 2 commits into
Conversation
ccoVeille
left a comment
There was a problem hiding this comment.
I appreciate you used go-yaml and our YAML test suite.
I feel like the fix is good.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7129c54 to
d1be72c
Compare
yxshee
left a comment
There was a problem hiding this comment.
I ran this merged onto main 2008d62 (head d1be72c) through a structural comparison with libyaml (PyYAML's C loader) and the yaml npm package on 60,000 generated documents built from block scalars, document markers, directives, flow collections and anchors. go test ./... passes with the YAML Test Suite data.
On the documents where libyaml and the yaml package agree, go-yaml differed from them on 956 before the change and on 931 after it. The 25 that now match include |+\n---\n (two documents instead of a scalar containing ---), |-\n...\n and >\n---\nb: |\n t\n, and none that matched before stopped matching. Of the 14 other changed results, 10 now match the yaml package where libyaml rejects the document (e.g. |+\n...\n- a gives "" then [a]), 3 now fail like libyaml (|+\n---\n*x and the like, where *x refers to no anchor), and one, \n...\n|+\n---\n, matches neither before or after because go-yaml does not emit the empty document before the leading .... So I could not find an input that gets worse.
|
@yxshee thanks for running this, that is a much wider check than the YAML Test Suite cases I used. The |
@yxshee Interesting, can you share how you generate or fetch these YAML documents to run your tests? This reminds me about something @Fredi told me about what he did for his own go-yaml package |
|
@ingydotnet this is approved by ccoVeille, and a 60k-document differential check found no regressions. Could you take a look and merge it if it looks right? |
d1be72c to
81f9ef3
Compare
A block scalar whose content starts at column 1 (a top-level
--- |or--- >) runs straight through a---or...line and eats the rest of the stream:Expected
"foo\n"and"x". The spec doesn't allow document markers inside block scalar content (c-forbidden, Example 9.5 / YTS W4TN). The plain and quoted scalar scanners already stop at a marker; the block scalar loop never checked for one.This adds the check to
scanBlockScalarand moves the existing inline check from the plain and quoted scanners into a smallisDocumentIndicatorhelper so all three use the same one. Nested block scalars can't have content at column 1, so only top-level ones are affected. Lines like----,...xor---are still content.Two scanner tests added (literal +
..., folded +---), plus tests forisDocumentIndicator. The scanner tests fail on main and pass here;go test ./...passes. W4TN stays inknown-failing-testsbecause it starts with%YAML 1.2, which the parser still rejects. That change will come as a separate PR after this one.Written with AI assistance (Claude); I have reviewed the change.