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
comments are not properly preserved following folded/literal string #326
Comments
I have done some more digging for this and the issue lies in the scanner; it does not correctly mark token positions for the folded/literal string types. This can be seen in the token stream for the YAML text in the issue. We can see that the literal token has both a negative column and the line corresponds to the token end (line 7) rather than the token start (line 5). https://go.dev/play/p/Yp6FW_SxuXh
This looks like it is happening here because the buffer size is being used to calculate the column and the function assumes that the token is a single line (it looks like this is touched elsewhere, but that code doesn't seem to repair the issue). Line 67 in dc3fed8
Ultimately, the association of the comment with the wrong node happens becuase here the lines match incorrectly. Line 483 in dc3fed8
|
If a comment follows a field using folded or literal style strings, the first line of the comment is lost, for example (https://play.golang.com/p/mN4v86pSwP8 https://play.golang.com/p/xHeGkd9bxDu https://play.golang.com/p/uzQ8WGzA4gs https://play.golang.com/p/wDYKVpHPdSL)
becomes
This does not happen with quoted or unquoted strings (https://play.golang.com/p/dc2RCZmRrIR https://play.golang.com/p/tjBLgB8OaG9).
This appears to be due to incorrect association of comments with nodes in the AST during parsing.
The YAML document above has the following AST comment associations (https://play.golang.com/p/3WtBBjARGXF)
Where we can see that the first line of the comments is incorrectly associated with the key2 node, but is not emitted, and the second line is correctly associated with the first element of the sequence via the
ValueComments
slice.The text was updated successfully, but these errors were encountered: