diff --git a/commons/lib/Logger.ts b/commons/lib/Logger.ts index 97c4e03..16d177a 100644 --- a/commons/lib/Logger.ts +++ b/commons/lib/Logger.ts @@ -125,8 +125,13 @@ class Log implements ILog { } } -function translateValueToPrintable(value: any, depth = 0): any { +function translateValueToPrintable(key: string, value: any, depth = 0): any { if (value === undefined || value === null) return; + + if (key === 'password' || key === 'suri') { + return '********'; + } + if (value instanceof Error) { return value.toString(); } @@ -153,11 +158,11 @@ function translateValueToPrintable(value: any, depth = 0): any { if (typeof value === 'object') { if (Array.isArray(value)) { - return value.map(x => translateValueToPrintable(x, depth + 1)); + return value.map((x, i) => translateValueToPrintable(i as any, x, depth + 1)); } const result: any = {}; - for (const [key, subValue] of Object.entries(value)) { - result[key] = translateValueToPrintable(subValue, depth + 1); + for (const [subKey, subValue] of Object.entries(value)) { + result[subKey] = translateValueToPrintable(subKey, subValue, depth + 1); } return result; } @@ -191,7 +196,7 @@ export function translateToPrintable( continue; } - const printable = translateValueToPrintable(value); + const printable = translateValueToPrintable(key, value); if (printable === null || printable === undefined) continue; printData[key] = printable; } diff --git a/commons/lib/TypeSerializer.ts b/commons/lib/TypeSerializer.ts index 2e9363e..8a76b6d 100644 --- a/commons/lib/TypeSerializer.ts +++ b/commons/lib/TypeSerializer.ts @@ -173,8 +173,9 @@ export default class TypeSerializer { } if (ArrayBuffer.isView(value)) { - // @ts-ignore - const binary = new TextDecoder('utf8').decode(value.buffer); + const binary = Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) + .map(byte => String.fromCharCode(byte)) + .join(''); return { __type: Types.ArrayBuffer64, value: globalThis.btoa(binary), @@ -186,8 +187,7 @@ export default class TypeSerializer { }; } if (value instanceof ArrayBuffer) { - // @ts-ignore - const binary = new TextDecoder('utf8').decode(value); + const binary = Array.from(new Uint8Array(value)).map(byte => String.fromCharCode(byte)).join(''); return { __type: Types.ArrayBuffer64, value: globalThis.btoa(binary), @@ -219,8 +219,10 @@ export default class TypeSerializer { } const decoded = globalThis.atob(value); - // @ts-ignore - const uint8Array = new TextEncoder().encode(decoded); + const uint8Array = new Uint8Array(new ArrayBuffer(decoded.length)); + for (let i = 0; i < decoded.length; i++) { + uint8Array[i] = decoded.charCodeAt(i); + } if (!entry.args) return uint8Array; const { arrayType, byteOffset, byteLength } = entry.args;