Skip to content

Commit a5fe327

Browse files
committed
fix: address bot review feedback for psql
- Fix prototype pollution in parser: use Object.create(null) for variables - Fix -f flag: update getSqlToExecute to handle file input correctly - Add 25 unit tests covering all functionality
1 parent 8af6f1f commit a5fe327

File tree

5 files changed

+538
-7
lines changed

5 files changed

+538
-7
lines changed

src/commands/psql/connection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ export function buildConnectionOptions(
2828

2929
/**
3030
* Get SQL to execute from options
31+
* Returns empty string only if no SQL source is available (no -c, no -f, no stdin)
3132
*/
3233
export function getSqlToExecute(options: PsqlOptions, stdin: string): string {
34+
// -c takes precedence
3335
if (options.command) {
3436
return options.command;
3537
}
3638

39+
// -f will be read later, return placeholder
40+
if (options.file) {
41+
return "FILE"; // Non-empty placeholder to pass validation
42+
}
43+
44+
// Check stdin
3745
if (stdin.trim()) {
3846
return stdin.trim();
3947
}

src/commands/psql/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function parseArgs(args: string[]): PsqlOptions | ExecResult {
2929
tuplesOnly: false,
3030
quiet: false,
3131
singleTransaction: false,
32-
variables: {},
32+
variables: Object.create(null) as Record<string, string>,
3333
};
3434

3535
let i = 0;

0 commit comments

Comments
 (0)