Skip to content

Commit

Permalink
psql: Add ignore_slash_options in bind's inactive branch
Browse files Browse the repository at this point in the history
All commands accepting arguments, handling them with OT_NORMAL, OT_SQLID
or OT_SQLIDHACK, should call ignore_slash_options() in inactive branch
to scan and discard extra arguments.  All the backslash commands that
handle arguments do so, except \bind.

This commit adds the missing ignore_slash_options to \bind's inactive
branch.  This inconsistency is a logic bug, however the behavior happens
to be unchanged as any extra arguments are discarded later in
HandleSlashCmds(), so no backpatch is done.

While on it, this adds \bind to the list of backslash commands where
inactive \if branches are checked in the tests for psql.

Reported-by: Jelte Fennema-Nio
Author: Anthonin Bonnefoy
Discussion: https://postgr.es/m/CAGECzQR1+udGKz+FbHiCQ7CWDiF1fCGi2xYuvQUODdMAfJbaLA@mail.gmail.com
  • Loading branch information
michaelpq committed Jan 19, 2024
1 parent 3ada0d2 commit 04c0897
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bin/psql/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ exec_command_bind(PsqlScanState scan_state, bool active_branch)
pset.bind_nparams = nparams;
pset.bind_flag = true;
}
else
ignore_slash_options(scan_state);

return status;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/psql.out
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,7 @@ bar 'bar' "bar"
\echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
\a
SELECT $1 \bind 1 \g
\C arg1
\c arg1 arg2 arg3 arg4
\cd arg1
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/sql/psql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ select \if false \\ (bogus \else \\ 42 \endif \\ forty_two;
\echo `nosuchcommand` :foo :'foo' :"foo"
\pset fieldsep | `nosuchcommand` :foo :'foo' :"foo"
\a
SELECT $1 \bind 1 \g
\C arg1
\c arg1 arg2 arg3 arg4
\cd arg1
Expand Down

0 comments on commit 04c0897

Please sign in to comment.