ecpg: avoid adding whitespace around '&' in connection URLs.
authorTom Lane <[email protected]>
Fri, 4 Oct 2024 16:01:50 +0000 (12:01 -0400)
committerTom Lane <[email protected]>
Fri, 4 Oct 2024 16:01:50 +0000 (12:01 -0400)
The preprocessor really should not have done this to begin with.
The space after '&' was masked by ECPGconnect's skipping spaces
before option keywords, and the space before by dint of libpq
being (mostly) insensitive to trailing space in option values.
We fixed the one known problem with that in 920d51979.  Hence
this patch is mostly cosmetic, and we'll just change it in HEAD.

Discussion: https://postgr.es/m/TY2PR01MB36286A7B97B9A15793335D18C1772@TY2PR01MB3628.jpnprd01.prod.outlook.com

src/interfaces/ecpg/ecpglib/connect.c
src/interfaces/ecpg/preproc/ecpg.trailer
src/interfaces/ecpg/test/expected/connect-test5.c
src/interfaces/ecpg/test/expected/connect-test5.stderr

index 8afb1f0a26fba3c0e7bbe8168dfad920bcc75a80..b24b310ce59d48404f864e5e6f1b15dfb0545012 100644 (file)
@@ -579,7 +579,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
         * The options string contains "keyword=value" pairs separated by
         * '&'s.  We must break this up into keywords and values to pass to
         * libpq (it's okay to scribble on the options string).  We ignore
-        * spaces just before each keyword or value.
+        * spaces just before each keyword or value.  (The preprocessor used
+        * to add spaces around '&'s, making it necessary to ignore spaces
+        * before keywords here.  While it no longer does that, we still must
+        * skip spaces to support code compiled with older preprocessors.)
         */
        for (str = options; *str;)
        {
index b6233e5e5307ce44acbd7ad9b3e3b6efdc5aadb8..f3ab73bed616ac46cbad438801c16767af427211 100644 (file)
@@ -348,7 +348,7 @@ connect_options: ColId opt_opt_value
        if (strcmp($3, "&") != 0)
            mmerror(PARSE_ERROR, ET_ERROR, "unrecognized token \"%s\"", $3);
 
-       $$ = cat_str(3, make2_str($1, $2), $3, $4);
+       $$ = make3_str(make2_str($1, $2), $3, $4);
    }
    ;
 
index ec1514ed9abe413c798c0a435bc3c5bfe6d46ce9..fc650f5cd57cb571896ace0b587154ea98b528db 100644 (file)
@@ -117,7 +117,7 @@ main(void)
 #line 56 "test5.pgc"
 
 
-   { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression?connect_timeout=180 & client_encoding=sql_ascii" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
+   { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression?connect_timeout=180&client_encoding=sql_ascii" , "regress_ecpg_user1" , "connectpw" , "main", 0); }
 #line 58 "test5.pgc"
 
    { ECPGdisconnect(__LINE__, "main");}
index 51cc18916a1fcb01e2f2a5892c3d7b4cf2bd422c..037db217586dd25f91a197cf1162021faed1826f 100644 (file)
@@ -50,7 +50,7 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection main closed
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGconnect: opening database ecpg2_regression on <DEFAULT> port <DEFAULT> with options connect_timeout=180 & client_encoding=sql_ascii for user regress_ecpg_user1
+[NO_PID]: ECPGconnect: opening database ecpg2_regression on <DEFAULT> port <DEFAULT> with options connect_timeout=180&client_encoding=sql_ascii for user regress_ecpg_user1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: connection main closed
 [NO_PID]: sqlca: code: 0, state: 00000