Skip to content

Commit 38930e0

Browse files
authored
Merge pull request #60 from kwonoj/skip-object-traverse
feat(loggerhelper): skip traverse object payload when there's no maskkey
2 parents f8cc886 + 3f90a79 commit 38930e0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/LoggerHelper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ export class LoggerHelper {
300300
keys: (number | string)[],
301301
maskPlaceholder: string
302302
): T {
303+
if (!Array.isArray(keys) || keys.length === 0) {
304+
return obj;
305+
}
306+
303307
const fn = (
304308
key: number | string,
305309
value: unknown

tests/settings.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,47 @@ describe("Logger: settings", () => {
780780
expect(stdStringGroups2?.[3]).toBe("[xxx]");
781781
});
782782

783+
test("init logger(type=json): empty maskValuesOfKeys", (): void => {
784+
const stdArray: string[] = [];
785+
const std: { write: (line: string) => void } = {
786+
write: (line: string) => {
787+
stdArray.push(line);
788+
},
789+
};
790+
const logger: Logger = new Logger({
791+
type: "json",
792+
maskValuesOfKeys: [],
793+
stdOut: std,
794+
stdErr: std,
795+
});
796+
let verySecretiveCircularObject = {
797+
password: "swordfish",
798+
Authorization: 1234567,
799+
stringPwd: "swordfish",
800+
nested: {
801+
regularString: "I am just a regular string.",
802+
otherString: "pass1234.567",
803+
},
804+
};
805+
verySecretiveCircularObject.nested[
806+
"circular"
807+
] = verySecretiveCircularObject;
808+
809+
const { argumentsArray } = logger.info(verySecretiveCircularObject);
810+
expect(argumentsArray[0]).toBe(verySecretiveCircularObject);
811+
812+
stdArray.length = 0;
813+
const undefinedMaskValuesLogger: Logger = new Logger({
814+
type: "json",
815+
maskValuesOfKeys: undefined,
816+
stdOut: std,
817+
stdErr: std,
818+
});
819+
820+
const { argumentsArray: undefinedMaskValuesArgArray } = undefinedMaskValuesLogger.info(verySecretiveCircularObject);
821+
expect(undefinedMaskValuesArgArray[0]).toBe(verySecretiveCircularObject);
822+
});
823+
783824
test("init logger(type=pretty): maskAnyRegEx", (): void => {
784825
const stdArray: string[] = [];
785826
const std: { write: (line: string) => void } = {

0 commit comments

Comments
 (0)