libpq: Improve error message when parsing URI parameters and keywords
authorMichael Paquier <[email protected]>
Tue, 19 Nov 2024 04:27:42 +0000 (13:27 +0900)
committerMichael Paquier <[email protected]>
Tue, 19 Nov 2024 04:27:42 +0000 (13:27 +0900)
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 430ce189fc45, hence there is no need for a
back.

Author: Yushi Ogiwara
Reviewed-by: Fujii Masao, Tom Lane, Bruce Momjian
Discussion: https://postgr.es/m/645bd22a53c4da8a1bc7e1e52d9d3b52@oss.nttdata.com

src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/t/001_uri.pl

index 51083dcfd8e4564e82f6e44745567ff6151e9992..aaf87e8e885fb2dcb98718ccb4f98b15f7861eca 100644 (file)
@@ -6825,7 +6825,9 @@ end:
    /* Not at the end of the string yet?  Fail. */
    if (*q != '\0')
    {
-       libpq_append_error(errorMessage, "trailing data found: \"%s\"", str);
+       libpq_append_error(errorMessage,
+                          "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
+                          str);
        free(buf);
        return NULL;
    }
index 27cf67ae8009044a80236a0a08c2320fbbbaf68b..2de2073e0a9fad1b38e4a010c587d73b9e6e4302 100644 (file)
@@ -96,13 +96,13 @@ my @tests = (
        # Trailing data in parameter.
        q{postgresql://host?  user user  =  uri  & port = 12345 12 },
        q{},
-       q{libpq_uri_regress: trailing data found: "  user user  "},
+       q{libpq_uri_regress: unexpected spaces found in "  user user  ", use percent-encoded spaces (%20) instead},
    ],
    [
        # Trailing data in value.
        q{postgresql://host?  user  =  uri-user  & port = 12345 12 },
        q{},
-       q{libpq_uri_regress: trailing data found: " 12345 12 "},
+       q{libpq_uri_regress: unexpected spaces found in " 12345 12 ", use percent-encoded spaces (%20) instead},
    ],
    [ q{postgresql://host?}, q{host='host' (inet)}, q{}, ],
    [