summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-09-18 21:28:30 +0800
committerGitHub <noreply@github.com>2020-09-18 09:28:30 -0400
commit38196f7850d7498e98f5ec7c66801deadabe09cf (patch)
tree268759120f366d4ce0ef38b441c81e51fd6037dc /std
parent7845740637eb646c0b13dc541f043fd65136fc03 (diff)
fix(cli/console): always quote and escape inspected strings (#7546)
Diffstat (limited to 'std')
-rw-r--r--std/fmt/printf_test.ts10
-rw-r--r--std/node/assertion_error_test.ts2
-rw-r--r--std/testing/asserts.ts8
3 files changed, 11 insertions, 9 deletions
diff --git a/std/fmt/printf_test.ts b/std/fmt/printf_test.ts
index 54adc8b55..81e172f81 100644
--- a/std/fmt/printf_test.ts
+++ b/std/fmt/printf_test.ts
@@ -655,8 +655,14 @@ Deno.test("testErrors", function (): void {
assertEquals(S("%[1]*.2f", "a", "p"), "%!(BAD WIDTH 'a')");
- assertEquals(S("A", "a", "p"), "A%!(EXTRA 'a' 'p')");
- assertEquals(S("%[2]s %[2]s", "a", "p"), "p p%!(EXTRA 'a')");
+ assertEquals(
+ S("A", "a", "p"),
+ `A%!(EXTRA '\x1b[32m"a"\x1b[39m' '\x1b[32m"p"\x1b[39m')`,
+ );
+ assertEquals(
+ S("%[2]s %[2]s", "a", "p"),
+ `p p%!(EXTRA '\x1b[32m"a"\x1b[39m')`,
+ );
// remains to be determined how to handle bad indices ...
// (realistically) the entire error handling is still up for grabs.
diff --git a/std/node/assertion_error_test.ts b/std/node/assertion_error_test.ts
index b0457fe5f..5157ea3b3 100644
--- a/std/node/assertion_error_test.ts
+++ b/std/node/assertion_error_test.ts
@@ -108,7 +108,7 @@ Deno.test({
stackStartFn,
});
assertStrictEquals(err.name, "AssertionError");
- assertStrictEquals(stripColor(err.message), "deno match /node/");
+ assertStrictEquals(stripColor(err.message), `"deno" match /node/`);
assertStrictEquals(err.generatedMessage, true);
assertStrictEquals(err.code, "ERR_ASSERTION");
assertStrictEquals(err.actual, "deno");
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index a3f0c1338..9796c9d31 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -20,7 +20,7 @@ export class AssertionError extends Error {
}
export function _format(v: unknown): string {
- let string = globalThis.Deno
+ return globalThis.Deno
? stripColor(Deno.inspect(v, {
depth: Infinity,
sorted: true,
@@ -28,11 +28,7 @@ export function _format(v: unknown): string {
compact: false,
iterableLimit: Infinity,
}))
- : String(v);
- if (typeof v == "string") {
- string = `"${string.replace(/(?=["\\])/g, "\\")}"`;
- }
- return string;
+ : `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
}
function createColor(diffType: DiffType): (s: string) => string {