From 38196f7850d7498e98f5ec7c66801deadabe09cf Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Fri, 18 Sep 2020 21:28:30 +0800 Subject: fix(cli/console): always quote and escape inspected strings (#7546) --- std/testing/asserts.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'std/testing') 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 { -- cgit v1.2.3