mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix(cli/console): always quote and escape inspected strings (denoland/deno#7546)
This commit is contained in:
parent
6862d1b79f
commit
ec04cb2584
@ -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.
|
||||
|
@ -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");
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user