From 5e892a65d65c899be251418f89283e374a485f8c Mon Sep 17 00:00:00 2001
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Date: Thu, 18 Jan 2024 08:34:26 +0100
Subject: [PATCH v4 1/2] psql: Add ignore_slash_options in bind's inactive
 branch

All commands accepting arguments call ignore_slash_options in inactive
branch to scan and discard extra arguments except bind.

This commit adds the missing ignore_slash_options to bin'd inactive
branch. The behaviour is unchanged as those extra arguments are
discarded later in HandleSlashCmds.
---
 src/bin/psql/command.c             | 2 ++
 src/test/regress/expected/psql.out | 1 +
 src/test/regress/sql/psql.sql      | 1 +
 3 files changed, 4 insertions(+)

diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 9ad911e28d..5c906e4806 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -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;
 }
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 4f3fd46420..ad02772562 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -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
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index c997106b9f..129f853353 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -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
-- 
2.39.3 (Apple Git-145)

