mirror of
https://github.com/apple/pkl.git
synced 2026-05-02 21:24:18 +02:00
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:
36
pkl-core/src/test/files/LanguageSnippetTests/input/api/yamlRenderer9.yml.pkl
vendored
Normal file
36
pkl-core/src/test/files/LanguageSnippetTests/input/api/yamlRenderer9.yml.pkl
vendored
Normal 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 {}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
15
pkl-core/src/test/files/LanguageSnippetTests/output/api/yamlRenderer9.yml
vendored
Normal file
15
pkl-core/src/test/files/LanguageSnippetTests/output/api/yamlRenderer9.yml
vendored
Normal 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"
|
||||
Reference in New Issue
Block a user