diff --git a/src/format.ts b/src/format.ts index 3a46888..96b02b5 100644 --- a/src/format.ts +++ b/src/format.ts @@ -15,18 +15,17 @@ const ErrorType = type({ "stack?": "string", }); -const formatItem = (item: unknown): string => { +const itemToString = (item: unknown): string => { if (typeof item === "undefined") return "undefined"; // Remove colors from strings if (typeof item === "string") // biome-ignore lint/suspicious/noControlCharactersInRegex: stripping ANSI escape codes - return config.redact(item.replace(/\x1b\[[0-9;]*m/g, "")); + return item.replace(/\x1b\[[0-9;]*m/g, ""); // Check if this is an Error const error = ErrorType(item); - if (!(error instanceof type.errors)) - return config.redact(error.stack || error.message); + if (!(error instanceof type.errors)) return error.stack || error.message; const stringified = (() => { try { @@ -36,12 +35,10 @@ const formatItem = (item: unknown): string => { } })(); - return config.redact(stringified.replace(/^'|'$/g, "")); + return stringified.replace(/^'|'$/g, ""); }; const format = (items: unknown[]): string => - Array.from(items) - .map((item) => formatItem(item)) - .join(" "); + config.redact(Array.from(items).map(itemToString).join(" ")); export { format, updateConfig }; diff --git a/tests/index.test.ts b/tests/index.test.ts index 07d04d9..a07af04 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -3,7 +3,7 @@ import { format } from "../src/format.js"; import { setupLogging } from "../src/index.js"; beforeAll(() => { - setupLogging(); + setupLogging({ hex: { allow: [{ re: /\b(transfer)\b/i }] } }); }); describe("logging", () => { @@ -34,4 +34,14 @@ describe("logging", () => { expect(result).not.toContain(secret); expect(result).toContain("[REDACTED]"); }); + + it("allows hex when context word is in a separate argument", () => { + const result = format([ + "transfer", + "538845bf2f418e0c7f3798d6bcb632273d46633545a5e261feceb7d378ed0761", + ]); + expect(result).toBe( + "transfer 538845bf2f418e0c7f3798d6bcb632273d46633545a5e261feceb7d378ed0761", + ); + }); });