You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the string contains newlines, it should be formatted as a multi-line string with |.
However, when the string has a space before \n, it does not work.
use serde::Serialize;#[derive(Serialize,Debug)]structFoo{v1:String,v2:String,}fnmain(){let a = Foo{v1:"a\nc".to_string(),v2:"a \nc".to_string(),};let yaml = serde_yaml_ng::to_string(&a).unwrap();println!("{}", yaml);}
v1: |- a cv2: "a \nc"
The text was updated successfully, but these errors were encountered:
It is unclear to me who is responsible for this "issue". And I'm not fluent in enough libyaml to give you a definite answer.
All I can say is that the libyaml was originally written for Python. And there is a similar behavior there:
>>> import yaml
>>> print(yaml.dump({'v1': 'a\nc', 'v2': 'a \nc'}))
v1: 'a
c'
v2: "a \nc"
So I suspect, that the culprit is the libyaml. Either way, this won't get fixed for two reasons: I'm not going to recompile the libyaml to Rust, because I find it to be an heresy. And, I actually want to migrate to libyaml-safer as mentioned in #5. I've been working slowly on this as there is a lot of refactoring necessary for this move.
But regardless of the move, I am unsure how this is a bug. Yeah, it doesn't look neat, I'll grant you this. But deserialize(serialize(data)) = data is still valid, right? This is valid YAML being generated. And one could argue that the current serialization makes it obvious that there are trailing spaces, right?
I'll leave this issue open as documentation, and see what we can do once we fix #5.
If the string contains newlines, it should be formatted as a multi-line string with
|
.However, when the string has a space before
\n
, it does not work.The text was updated successfully, but these errors were encountered: