Skip to content

Commit

Permalink
Handle objects that can't be cloned recursively. Fix Ã#93
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Mar 11, 2021
1 parent 6a9e1bf commit 030c203
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/LoggerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ export class LoggerHelper {
return LoggerHelper.cloneObjectRecursively(value, maskValuesFn, done);
}
}) as unknown) as T;
} else if (Buffer.isBuffer(obj)) {
return obj as T;
} else {
Object.getOwnPropertyNames(obj).forEach((currentKey: string | number) => {
if (!done.includes(obj[currentKey])) {
Expand Down
11 changes: 9 additions & 2 deletions src/LoggerWithoutCallSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,15 @@ export class LoggerWithoutCallSite {
object: object | null,
options: InspectOptions
): string {
const maskedObject = this._maskValuesOfKeys(object);
return this._maskAny(inspect(maskedObject, options));
let formatted;
try {
const maskedObject = this._maskValuesOfKeys(object);
formatted = format(maskedObject, options);
} catch {
formatted = format(object, options);
}

return this._maskAny(formatted);
}

private _formatAndHideSensitive(
Expand Down
10 changes: 9 additions & 1 deletion tests/parameter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "ts-jest";
import { IStd, Logger } from "../src";
import { doesLogContain } from "./helper";
import exp = require("constants");
import { URL } from "url";

const stdOut: string[] = [];
const stdErr: string[] = [];
Expand Down Expand Up @@ -135,4 +135,12 @@ describe("Logger: Parameter", () => {
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "<Buffer 66 6f 6f>")).toBeTruthy();
});

test("Url", (): void => {
const url = new URL("http://example.com");
logger.silly(url);

expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
expect(doesLogContain(stdOut, "http://example.com/")).toBeTruthy();
});
});

0 comments on commit 030c203

Please sign in to comment.