Skip to content

Commit a3699da

Browse files
committed
libpq: Improve error message when parsing URI parameters and keywords
The error message showing up when parameters or keywords include too many whitespaces was "trailing data found", which was confusing because there was no hint about what was actually wrong. Issue introduced in 430ce18, hence there is no need for a backpatch. Author: Yushi Ogiwara Reviewed-by: Fujii Masao, Tom Lane, Bruce Momjian Discussion: https://postgr.es/m/[email protected]
1 parent b38bac2 commit a3699da

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/interfaces/libpq/fe-connect.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -6825,7 +6825,9 @@ conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
68256825
/* Not at the end of the string yet? Fail. */
68266826
if (*q != '\0')
68276827
{
6828-
libpq_append_error(errorMessage, "trailing data found: \"%s\"", str);
6828+
libpq_append_error(errorMessage,
6829+
"unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
6830+
str);
68296831
free(buf);
68306832
return NULL;
68316833
}

src/interfaces/libpq/t/001_uri.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@
9696
# Trailing data in parameter.
9797
q{postgresql://host? user user = uri & port = 12345 12 },
9898
q{},
99-
q{libpq_uri_regress: trailing data found: " user user "},
99+
q{libpq_uri_regress: unexpected spaces found in " user user ", use percent-encoded spaces (%20) instead},
100100
],
101101
[
102102
# Trailing data in value.
103103
q{postgresql://host? user = uri-user & port = 12345 12 },
104104
q{},
105-
q{libpq_uri_regress: trailing data found: " 12345 12 "},
105+
q{libpq_uri_regress: unexpected spaces found in " 12345 12 ", use percent-encoded spaces (%20) instead},
106106
],
107107
[ q{postgresql://host?}, q{host='host' (inet)}, q{}, ],
108108
[

0 commit comments

Comments
 (0)