Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit390298f

Browse files
committed
Allow noise semicolons ending psql \sf, \ef, \sv, \ev commands.
Many psql backslash commands tolerate trailing semicolons, eventhough that's not part of the official syntax. These did not.They tried to, by passing semicolon = true to psql_scan_slash_option,but that function ignored this parameter in OT_WHOLE_LINE mode.Teach it to do the right thing, and remove the now-duplicativelogic in exec_command_help.Discussion:https://postgr.es/m/2012251.1704746912@sss.pgh.pa.us
1 parentadd673b commit390298f

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

‎src/bin/psql/command.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,18 +1640,7 @@ exec_command_help(PsqlScanState scan_state, bool active_branch)
16401640
if (active_branch)
16411641
{
16421642
char*opt=psql_scan_slash_option(scan_state,
1643-
OT_WHOLE_LINE,NULL, false);
1644-
size_tlen;
1645-
1646-
/* strip any trailing spaces and semicolons */
1647-
if (opt)
1648-
{
1649-
len=strlen(opt);
1650-
while (len>0&&
1651-
(isspace((unsignedchar)opt[len-1])
1652-
||opt[len-1]==';'))
1653-
opt[--len]='\0';
1654-
}
1643+
OT_WHOLE_LINE,NULL, true);
16551644

16561645
helpSQL(opt,pset.popt.topt.pager);
16571646
free(opt);
@@ -3151,6 +3140,10 @@ ignore_slash_filepipe(PsqlScanState scan_state)
31513140
* This *MUST* be used for inactive-branch processing of any slash command
31523141
* that takes an OT_WHOLE_LINE option. Otherwise we might consume a different
31533142
* amount of option text in active and inactive cases.
3143+
*
3144+
* Note: although callers might pass "semicolon" as either true or false,
3145+
* we need not duplicate that here, since it doesn't affect the amount of
3146+
* input text consumed.
31543147
*/
31553148
staticvoid
31563149
ignore_slash_whole_line(PsqlScanStatescan_state)

‎src/bin/psql/psqlscanslash.l

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
#include "postgres_fe.h"
2020

21+
#include <ctype.h>
22+
2123
#include "common.h"
2224
#include "psqlscanslash.h"
2325

@@ -608,7 +610,7 @@ psql_scan_slash_option(PsqlScanState state,
608610
/* empty arg */
609611
break;
610612
case xslasharg:
611-
/* Strip any unquoted trailingsemi-colons if requested */
613+
/* Strip any unquoted trailingsemicolons if requested */
612614
if (semicolon)
613615
{
614616
while (unquoted_option_chars-- >0 &&
@@ -640,7 +642,22 @@ psql_scan_slash_option(PsqlScanState state,
640642
termPQExpBuffer(&mybuf);
641643
returnNULL;
642644
case xslashwholeline:
643-
/* always okay */
645+
/*
646+
* In whole-line mode, we interpret semicolon = true as stripping
647+
* trailing whitespace as well as semicolons; this gives the
648+
* nearest equivalent to what semicolon = true does in normal
649+
* mode. Note there's no concept of quoting in this mode.
650+
*/
651+
if (semicolon)
652+
{
653+
while (mybuf.len >0 &&
654+
(mybuf.data[mybuf.len -1] ==';' ||
655+
(isascii((unsignedchar) mybuf.data[mybuf.len -1]) &&
656+
isspace((unsignedchar) mybuf.data[mybuf.len -1]))))
657+
{
658+
mybuf.data[--mybuf.len] ='\0';
659+
}
660+
}
644661
break;
645662
default:
646663
/* can't get here */

‎src/test/regress/expected/psql.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5323,7 +5323,7 @@ END
53235323
LANGUAGE sql
53245324
IMMUTABLE PARALLEL SAFE STRICT COST 1
53255325
1 RETURN ($2 + $1)
5326-
\sf ts_debug(text)
5326+
\sf ts_debug(text);
53275327
CREATE OR REPLACE FUNCTION pg_catalog.ts_debug(document text, OUT alias text, OUT description text, OUT token text, OUT dictionaries regdictionary[], OUT dictionary regdictionary, OUT lexemes text[])
53285328
RETURNS SETOF record
53295329
LANGUAGE sql

‎src/test/regress/sql/psql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ drop role regress_psql_user;
13151315
\sfinformation_schema._pg_index_position
13161316
\sf+information_schema._pg_index_position
13171317
\sf+ interval_pl_time
1318-
\sf ts_debug(text)
1318+
\sf ts_debug(text);
13191319
\sf+ ts_debug(text)
13201320

13211321
-- AUTOCOMMIT

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp