-
Notifications
You must be signed in to change notification settings - Fork 16
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
Default chomping indicator in ScalarStyle.LITERAL
#86
Comments
@jonasfj should the string from the user be preserved "as is" when inserting it in the yaml or should we mutate it to match the behaviour of By "as-is", I mean should we respect how the user wants it to look like when it is parsed by |
I'm not sure exactly what this means. If I do: final myString = 'my string....';
yamlEditor.update(['key'], myString);
final result = json.decode(json.encode(yamlEditor.parseAt([])));
assert(result['key'] == myString); Meaning, when I insert a string then, yes, when I parse the YAML document produced I expect I'll get the same string out. That's what makes literal and folded strings somewhat tricky. Example: try encoding Sometimes I suppose that using a chomping indicator might help. Many times I suspect we'll simply have to fallback to quoted string with escape characters The most important thing is that the result is correct, when parsed back. Producing the style requested is more of a best-effort approach. And yes, there clearly are hole in how all this logic works today. I don't know if we can always make the chomping indicator be |
That would result in To achieve:
The real pain is: I'll make a PR by the end of the day for your feedback and add this |
Yeah, I got this example wrong 🙈 Which probably is another example of how these strings are hard. But you do need the key1: >- # <-- omitting the chomping indicator will add \n at the end
foo
bar
key2: other-value It's easy to see this if you use a tool like: https://onlineyamltools.com/convert-yaml-to-json |
It seems
ScalarStyle.LITERAL
applies thestripping
chomping indicator-
by default.yaml_edit/lib/src/strings.dart
Lines 117 to 129 in 561309e
ScalarStyle.FOLDED
at least checks if there is any line break.yaml_edit/lib/src/strings.dart
Lines 92 to 115 in 561309e
Expected Behaviour
As indicated in the spec, we should check for both
line breaks
&trailing spaces
in order to apply the correct chomping indicator for block styles:-
for stripping any trailing line breaks/spaces (strip)+
for preserving trailing line breaks/spaces (keep)Ideally, we should end up using the
keep
chomping indicator+
only since we may have no use for thestrip
chomping indicator-
.Fixing this may have desirable ripple effects for #41 & #44.
The text was updated successfully, but these errors were encountered: