Skip to content
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

Customize yaml.Marshal wrap behavior #387

Open
nicksnyder opened this issue Jul 17, 2018 · 4 comments
Open

Customize yaml.Marshal wrap behavior #387

nicksnyder opened this issue Jul 17, 2018 · 4 comments

Comments

@nicksnyder
Copy link

The yaml.Marshal appears to split long string values on to multiple lines. Is there any way to prevent this from happening?

@nicksnyder nicksnyder changed the title Customize wrap behavior Customize yaml.Marshal wrap behavior Jul 17, 2018
@bgveenstra
Copy link

bgveenstra commented Aug 8, 2018

The added linebreaks were also unexpected for me (and causes the output not to work, in my case).

Also found an earlier report about this behavior being unexpected (#348).

The 80-character limit is set on the Encoder's emitter:

if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 {

I didn't see a way through the API to modify these settings, but I would definitely be excited to use one.

@DoubleLuck
Copy link

This feature confuses me too. I use this package to modify ConfigMap of k8s, but after an 'Unmarshal' and a 'Marshal' operations, the configmap appears more differences than I except. Hope for some APIs to define these settings.

@Aisuko
Copy link

Aisuko commented Dec 6, 2018

The same issue with you guys. I Marshal the data into a yaml text file, then the function generates an unexpected line break in the marshaled bytes array like below:

Input:

ssh_authorized_keys:- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2Sx8dhcxM16zUIJGUsoHvium2ezzXL5F5obBvWd441BSau1XTDVdO3zOchF3mWvYX5q4JT1CF4GntvM1vc16acuVmkzsjsDe3+4uVPPzJps01vDxVeV1vRM53P2deCUnrFJ48CvrPisyXSOCtUCRFC1pPdvVAnOyTkzboQkCEbt6551bXF2nTnZu7XOSdzAKj+YLIRNf/ecr4hJi9xW7Q4N6gP0C+zn/KjvFQ0QSN5t8Cpbg4ri7uR2Vd4a0ccyJ5TQLRJ3EtAvuVZK3CeY0B3/XlD31cLMSFgLpWDBU2p9OC27Lc3grcYL2kN1A1HsV5AjBWRfTnFuCcOQ7MNdjJ root@ip-xxx-xx-xx-xx

Output:

ssh_authorized_keys:- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2Sx8dhcxM16zUIJGUsoHvium2ezzXL5F5obBvWd441BSau1XTDVdO3zOchF3mWvYX5q4JT1CF4GntvM1vc16acuVmkzsjsDe3+4uVPPzJps01vDxVeV1vRM53P2deCUnrFJ48CvrPisyXSOCtUCRFC1pPdvVAnOyTkzboQkCEbt6551bXF2nTnZu7XOSdzAKj+YLIRNf/ecr4hJi9xW7Q4N6gP0C+zn/KjvFQ0QSN5t8Cpbg4ri7uR2Vd4a0ccyJ5TQLRJ3EtAvuVZK3CeY0B3/XlD31cLMSFgLpWDBU2p9OC27Lc3grcYL2kN1A1HsV5AjBWRfTnFuCcOQ7MNdjJ
  root@ip-xxx-xx-xx-xx

Is there any standard length about the best_width for golang's yaml?

Link issue 166

About yml Folded Style

@laverya
Copy link
Contributor

laverya commented Oct 15, 2020

Since this is getting mentioned, v2.3.0 fixes this by setting the default line length limit to -1 or infinity - see #571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants