Skip to content

Commit 9cd43f6

Browse files
committed
Fix busted tab completion of extension versions.
In 02b8048 I (tgl) got rid of the need for most tab-completion queries to return pre-quoted identifiers. But I over-hastily removed the quote_ident call from Query_for_list_of_available_extension_versions* too; those still need it, because what is returned isn't an identifier at all and will (almost?) always need quoting. Arguably we should use quote_literal here instead. But quote_ident works too and people may be used to that behavior, so stick with it. In passing, fix inconsistent omission of schema-qualification in Query_for_list_of_encodings. That's not a security issue per our current guidelines, but it ought to be like the rest. Jeff Janes Discussion: https://postgr.es/m/CAMkU=1yV+egSYrzWvbDY8VZ6bKEMrKbzxr-HTuiHi+wDgSUMgA@mail.gmail.com
1 parent 7bd4a9e commit 9cd43f6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/bin/psql/tab-complete.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ static bool completion_force_quote; /* true to force-quote filenames */
238238
* QUERY_PLUS forms combine such literal lists with a query result.
239239
* 4) The list of attributes of the given table (possibly schema-qualified).
240240
* 5) The list of arguments to the given function (possibly schema-qualified).
241+
*
242+
* The query is generally expected to return raw SQL identifiers; quoting
243+
* is handled by the matching machinery. If what is returned is not SQL
244+
* identifiers, use one of the VERBATIM forms (and then, if quoting is
245+
* needed, do it inside the query).
241246
*/
242247
#define COMPLETE_WITH_QUERY(query) \
243248
COMPLETE_WITH_QUERY_LIST(query, NULL)
@@ -992,7 +997,7 @@ static const SchemaQuery Query_for_trigger_of_table = {
992997
#define Query_for_list_of_encodings \
993998
" SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) "\
994999
" FROM pg_catalog.pg_conversion "\
995-
" WHERE pg_catalog.pg_encoding_to_char(conforencoding) LIKE UPPER('%s')"
1000+
" WHERE pg_catalog.pg_encoding_to_char(conforencoding) LIKE pg_catalog.upper('%s')"
9961001

9971002
#define Query_for_list_of_languages \
9981003
"SELECT lanname "\
@@ -1076,18 +1081,18 @@ static const SchemaQuery Query_for_trigger_of_table = {
10761081
" FROM pg_catalog.pg_available_extensions "\
10771082
" WHERE name LIKE '%s' AND installed_version IS NULL"
10781083

1079-
/* the result of this query is not an identifier, so use VERBATIM */
1084+
/* the result of this query is not a raw identifier, so use VERBATIM */
10801085
#define Query_for_list_of_available_extension_versions \
1081-
" SELECT version "\
1086+
" SELECT pg_catalog.quote_ident(version) "\
10821087
" FROM pg_catalog.pg_available_extension_versions "\
1083-
" WHERE version LIKE '%s'"\
1088+
" WHERE pg_catalog.quote_ident(version) LIKE '%s'"\
10841089
" AND name='%s'"
10851090

1086-
/* the result of this query is not an identifier, so use VERBATIM */
1091+
/* the result of this query is not a raw identifier, so use VERBATIM */
10871092
#define Query_for_list_of_available_extension_versions_with_TO \
1088-
" SELECT 'TO ' || version "\
1093+
" SELECT 'TO ' || pg_catalog.quote_ident(version) "\
10891094
" FROM pg_catalog.pg_available_extension_versions "\
1090-
" WHERE ('TO ' || version) LIKE '%s'"\
1095+
" WHERE ('TO ' || pg_catalog.quote_ident(version)) LIKE '%s'"\
10911096
" AND name='%s'"
10921097

10931098
#define Query_for_list_of_prepared_statements \

0 commit comments

Comments
 (0)