-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
yaml.Marshal(...): adds an (for me) unwanted \n #355
Comments
Thanks for the report, but AFAICS the extra newline is being printed because you're using fmt.Println not fmt.Print. If you use fmt.Print, there is no extra newline printed. Therefore I'm going to close this issue as invalid. |
@rogpeppe thank you for the reply! There is a new line added in the end of the string by the If this is wanted or unwanted behavior can boil down to the question if it
|
Newlines are a significant part of the YAML format. Why do you think it's a good idea that a formatted YAML file should not contain a final newline? |
I'm not confident that it would make sense for this repo to add a new line. I'm thinking that the benefit of not including it would allow a user to choose to end with a new line or not by the usage of "println" / "print" or similar function. No matter if that would make sense, it might become an issue switching to not include a \n now for current users being accustomed to it. The yaml.Marshal function is in my case not used to write a full YAML file, but a part of it. I'm using Kubernetes/Helm that has declared a toYaml function that outputs yaml snippets based on github.com/ghodss/yaml which is wrapping for this repo. I'll close this as it seems like the current behavior is the generally expected behavior. |
The yaml format is inherently multi-line, and indented, so having the new line there seems appropriate, and as you hint stripping it is trivial. If someone is dealing with yaml snippets, they are already into byte-fiddling territory anyway because they will have to reindent the output to match the context. |
For me, it is an unwanted behavior that a new line is popping up in the string after using the
yaml.Marshal(...)
function. Does it make sense to fix this? I arrive here through Helm issue #3470 and have traced the origin of that issue to this behavior of theyaml.Marshal
function. The Helm repo could circumvent it by trimming the new line as well.Reproduction
The text was updated successfully, but these errors were encountered: