-
Notifications
You must be signed in to change notification settings - Fork 35
Multiline scalars w/ trailing ws can emit literal #79
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where multiline scalars with trailing whitespace can now emit literal scalar style in YAML. The changes modify the scalar analysis logic to allow literal block style for scalars that contain space-break patterns, while maintaining restrictions for other cases.
Key changes:
- Updated scalar analysis function to check event scalar style before disallowing block literals
- Modified test expectations to reflect literal scalar output instead of double-quoted strings
- Added new test case for middle lines ending with spaces
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| emitterc.go | Modified scalar analysis logic to allow literal block style for space-break patterns when explicitly requested |
| encode_test.go | Updated test expectations and added new test case to verify literal scalar output for multiline strings with trailing whitespace |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
I have some issues with this fix.
That means it also changes In v4 I'd like to have a lot more options on how things are emitted. I'd like to hear your thoughts. (Yes, you!) |
|
I get the impression from Lines 433 to 434 in 7f7bed1
After all, it seems that Lines 540 to 554 in 7f7bed1
And, when decoding a literal string to a |
| "|\n hello \n", | ||
| "Text + spaces + newline - should be double quoted (ends with spaces)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You talked about the change here
There is clear problem indeed
Not only the format changes (why not, after all) , but here the trailing spaces before the \n are lost
I feel like it's not a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only the format changes (why not, after all) , but here the trailing spaces before the \n are lost
I'm confused.
How are they lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry. I feel like my comment was based on a misunderstanding.
Now, I feel like I didn't understand clearly what your change is about.
The spaces are indeed there. I was confused by the presence of \n as a first character of the marshaled.
I feel like I didn't understand the change involved here. So I'll pass on this PR.
Fixes #78
When go-yaml encodes a Node it tries to use the style that the node was assigned. In this case the style is "Literal" (the YAML style that uses a
|).But it has to then look at the value to see if the string can even be emitted in the literal style.
Only double quoted style can encode any possible string value.
If it doesn't think it can or should use the literal style it switches to double quoted.
I relaxed the rule a bit.
It wasn't allowing any line with a space before a linebreak.