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
I need to encode multi-line strings within a record, that often contain quotes. As well, I have octal permissions such as 0644 that yaml would parse as an octal numeric literal. I would expect Encode.string to either properly escape and quote this, or generate a yaml multi-line string block.
escapeme: "0700"oneline: "multi line string\nwith \"quoted\" text"multiline: |- multi line string with "quoted" text
For now I'm working around this with the following:
safeEncodeString:String->YE.EncodersafeEncodeString =
encodeNewlines
>> encodeQuotes
>>String.Extra.quote
>>YE.string
encodeNewlines:String->StringencodeNewlines =String.replace "\n""\\n"encodeQuotes:String->StringencodeQuotes s =if String.contains "\"" s thenString.replace "\"""\\\"" s
else
s
record keys may be parsed in odd ways, and the easy approach may just be to quote them all
strings starting with an asterisk (references), exclamation point (tags), and ampersand (anchors) must be quoted
I'm of the opinion that yaml encoding here should be as aggressively safe as possible, and parsing and encoded document should be identical regardless of the yaml specification used when parsing. String escaping and quoting should probably be the default, and multi-line strings might just be too problematic to deal with (at the minimum, needing to handle trailing newlines properly)
The text was updated successfully, but these errors were encountered:
I need to encode multi-line strings within a record, that often contain quotes. As well, I have octal permissions such as
0644
that yaml would parse as an octal numeric literal. I would expectEncode.string
to either properly escape and quote this, or generate a yaml multi-line string block.For now I'm working around this with the following:
Edit:
While reading https://ruudvanasseldonk.com/2023/01/11/the-yaml-document-from-hell for other potential pitfalls, I've noted:
I'm of the opinion that yaml encoding here should be as aggressively safe as possible, and parsing and encoded document should be identical regardless of the yaml specification used when parsing. String escaping and quoting should probably be the default, and multi-line strings might just be too problematic to deal with (at the minimum, needing to handle trailing newlines properly)
The text was updated successfully, but these errors were encountered: