mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(cli/console): escape non printable characters in object entries (#7533)
This commit is contained in:
parent
c307e3e4be
commit
a6f4559174
2 changed files with 20 additions and 7 deletions
|
@ -462,7 +462,11 @@
|
|||
.replace(/\n/g, "\\n")
|
||||
.replace(/\r/g, "\\r")
|
||||
.replace(/\t/g, "\\t")
|
||||
.replace(/\v/g, "\\v");
|
||||
.replace(/\v/g, "\\v")
|
||||
.replace(
|
||||
/[\x00-\x1f\x7f-\x9f]/g,
|
||||
(c) => "\\x" + c.charCodeAt(0).toString(16).padStart(2, "0"),
|
||||
);
|
||||
}
|
||||
|
||||
// Print strings when they are inside of arrays or objects with quotes
|
||||
|
|
|
@ -94,16 +94,25 @@ unitTest(function consoleTestStringifyComplexObjects(): void {
|
|||
unitTest(
|
||||
function consoleTestStringifyComplexObjectsWithEscapedSequences(): void {
|
||||
assertEquals(
|
||||
stringify(["foo\b", "foo\f", "foo\n", "foo\r", "foo\t", "foo\v"]),
|
||||
`[ "foo\\b", "foo\\f", "foo\\n", "foo\\r", "foo\\t", "foo\\v" ]`,
|
||||
stringify(
|
||||
["foo\b", "foo\f", "foo\n", "foo\r", "foo\t", "foo\v", "foo\0"],
|
||||
),
|
||||
`[
|
||||
"foo\\b", "foo\\f",
|
||||
"foo\\n", "foo\\r",
|
||||
"foo\\t", "foo\\v",
|
||||
"foo\\x00"
|
||||
]`,
|
||||
);
|
||||
assertEquals(
|
||||
stringify({ "foo\b": "bar\n", "bar\r": "baz\t" }),
|
||||
`{ foo\\b: "bar\\n", bar\\r: "baz\\t" }`,
|
||||
stringify(
|
||||
{ "foo\b": "bar\n", "bar\r": "baz\t", "qux\0": "qux\0" },
|
||||
),
|
||||
`{ foo\\b: "bar\\n", bar\\r: "baz\\t", qux\\x00: "qux\\x00" }`,
|
||||
);
|
||||
assertEquals(
|
||||
stringify(new Set(["foo\n", "foo\r"])),
|
||||
`Set { "foo\\n", "foo\\r" }`,
|
||||
stringify(new Set(["foo\n", "foo\r", "foo\0"])),
|
||||
`Set { "foo\\n", "foo\\r", "foo\\x00" }`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue