Skip to content

Commit 030c203

Browse files
committed
Handle objects that can't be cloned recursively. Fix Ã#93
1 parent 6a9e1bf commit 030c203

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/LoggerHelper.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ export class LoggerHelper {
294294
return LoggerHelper.cloneObjectRecursively(value, maskValuesFn, done);
295295
}
296296
}) as unknown) as T;
297-
} else if (Buffer.isBuffer(obj)) {
298-
return obj as T;
299297
} else {
300298
Object.getOwnPropertyNames(obj).forEach((currentKey: string | number) => {
301299
if (!done.includes(obj[currentKey])) {

src/LoggerWithoutCallSite.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,15 @@ export class LoggerWithoutCallSite {
893893
object: object | null,
894894
options: InspectOptions
895895
): string {
896-
const maskedObject = this._maskValuesOfKeys(object);
897-
return this._maskAny(inspect(maskedObject, options));
896+
let formatted;
897+
try {
898+
const maskedObject = this._maskValuesOfKeys(object);
899+
formatted = format(maskedObject, options);
900+
} catch {
901+
formatted = format(object, options);
902+
}
903+
904+
return this._maskAny(formatted);
898905
}
899906

900907
private _formatAndHideSensitive(

tests/parameter.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "ts-jest";
22
import { IStd, Logger } from "../src";
33
import { doesLogContain } from "./helper";
4-
import exp = require("constants");
4+
import { URL } from "url";
55

66
const stdOut: string[] = [];
77
const stdErr: string[] = [];
@@ -135,4 +135,12 @@ describe("Logger: Parameter", () => {
135135
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
136136
expect(doesLogContain(stdOut, "<Buffer 66 6f 6f>")).toBeTruthy();
137137
});
138+
139+
test("Url", (): void => {
140+
const url = new URL("http://example.com");
141+
logger.silly(url);
142+
143+
expect(doesLogContain(stdOut, "SILLY")).toBeTruthy();
144+
expect(doesLogContain(stdOut, "http://example.com/")).toBeTruthy();
145+
});
138146
});

0 commit comments

Comments
 (0)