(args: ReadonlyArray<unknown>)
| 47 | * Sanitizes the arguments of a command to remove sensitive information. |
| 48 | */ |
| 49 | export function sanitizeArgs(args: ReadonlyArray<unknown>): ReadonlyArray<string> { |
| 50 | if (args.length === 0) return []; |
| 51 | |
| 52 | const commandName = String(args[0]); |
| 53 | let allowedArgCount = 0; // default: command name only for unlisted commands |
| 54 | |
| 55 | for (const subset of SERIALIZATION_SUBSETS) { |
| 56 | if (subset.regex.test(commandName)) { |
| 57 | allowedArgCount = subset.args; |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // All args are safe (structural/read commands) |
| 63 | if (allowedArgCount === -1) { |
| 64 | return args.map(a => String(a)); |
| 65 | } |
| 66 | |
| 67 | const result: string[] = [commandName]; |
| 68 | for (let i = 1; i < args.length; i++) { |
| 69 | if (i <= allowedArgCount) { |
| 70 | result.push(String(args[i])); |
| 71 | } else { |
| 72 | result.push('?'); |
| 73 | } |
| 74 | } |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | export interface CommandTraceContext { |
| 79 | command: string; |
no test coverage detected