-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Multiline strings (or block scalars) are not preserved when they have trailing white space. #566
Comments
We have the same issue and its important for us because it destroys the configuration. |
Same here - is this something to be expected in |
Ok just discovered this is a duplicate of #1681 and #1277, which both depend on go-yaml/yaml#880 @mikefarah perhaps it would be best to close #1681 and #1277 as duplicates of this issue (since this one is the oldest) |
The reason #9312c1f did not preserve YAML multi-line block is due to a trailing space in one of the lines; this is a bug in "yq" documented in mikefarah/yq#566 which depends on go-yaml/yaml#880
I spent some time investigating this yesterday, and found the related code within I almost spent time working out a fix in the upstream library, but I'm wondering if @mikefarah would be open to another direction, i.e. using https://github.com/goccy/go-yaml/ for more of the standard parsing / lexing / encoding / decoding within yq. I see it's already in use for one specific use-case (colorized output), but it could likely be used to replace all It may be an undertaking, but as upstream of There's a simple
|
fwiw, these are the bits of the code in Determining if there are trailing spaces in a scalar: if is_space(value, i) {
if i == 0 {
leading_space = true
}
if i+width(value[i]) == len(value) {
trailing_space = true
}
...
}
... Disabling various ways to render based on trailing spaces being identified: if leading_space || leading_break || trailing_space || trailing_break {
emitter.scalar_data.flow_plain_allowed = false
emitter.scalar_data.block_plain_allowed = false
}
if trailing_space {
emitter.scalar_data.block_allowed = false
} The actual decision to render in double-quoted scalar format: if style == yaml_LITERAL_SCALAR_STYLE || style == yaml_FOLDED_SCALAR_STYLE {
if !emitter.scalar_data.block_allowed || emitter.flow_level > 0 || emitter.simple_key_context {
style = yaml_DOUBLE_QUOTED_SCALAR_STYLE
}
} |
Hi there, Mike! While mr. Niemeyer has sensible reasons not to allow other maintainers on the project, in fact the repo hasn't been touched for 2 years now. The suggested project seems a bit more alive, but in the end it's yet another single-person-team project :( It has a half of opened issues, although that also doesn't have to mean anything and I understand the risk of porting I'd say Thank you! |
I use the following as a workaround for now. It removes all trailing spaces from block literals.
|
Describe the bug
Multiline strings (or block scalars) are not preserved when they have trailing white space. They are converted to quoted strings.
version of yq: 3.3.4
operating system: Linux Mint 19
Input Yaml
Command
The command you ran:
Actual behavior
Expected behavior
The text was updated successfully, but these errors were encountered: