Fix escaping in yaml strings (#1165)

The backslash needs to be escaped when rendering double-quoted YAML strings.

In addition, this escapes the following characters:

* next line (0x85)
* nbsp (0xa0)
This commit is contained in:
Daniel Chao
2025-08-06 07:57:52 -07:00
committed by GitHub
parent 78ba6bf758
commit 7d50aaeec9
4 changed files with 82 additions and 9 deletions

View File

@@ -0,0 +1,36 @@
// test escaping in double quotes
// every string is prefixed with `\t` s.t. YamlRenderer will emit double-quoted strings.
`null` = "\t\u{00}"
bell = "\t\u{7}"
backspace = "\t\u{8}"
horizontalTab = "\t"
lineFeed = "\t\u{a}"
verticalTab = "\t\u{b}"
formFeed = "\t\u{c}"
carriageReturn = "\t\r"
escape = "\t\u{1b}"
doubleQuote = "\t\""
backslash = "\t\\"
nextLine = "\t\u{85}"
nbsp = "\t\u{a0}"
lineSep = "\t\u{2028}"
paragraphSep = "\t\u{2029}"
output {
renderer = new YamlRenderer {}
}

View File

@@ -114,12 +114,12 @@ examples {
render(".NAN")
render(".nAn") // never float
}
["tag like strings"] {
"!!bool true"
"!!str my string value"
}
["number like string keys"] {
render(new Dynamic {
`0` = "0"

View File

@@ -0,0 +1,15 @@
'null': "\t\0"
bell: "\t\a"
backspace: "\t\b"
horizontalTab: "\t"
lineFeed: "\t\n"
verticalTab: "\t\v"
formFeed: "\t\f"
carriageReturn: "\t\r"
escape: "\t\e"
doubleQuote: "\t\""
backslash: "\t\\"
nextLine: "\t\N"
nbsp: "\t\_"
lineSep: "\t\L"
paragraphSep: "\t\P"