|
26 | 26 | #endif
|
27 | 27 |
|
28 | 28 | #include "common/string.h"
|
| 29 | +#include "fe_utils/string_utils.h" |
29 | 30 | #include "getopt_long.h"
|
30 | 31 | #include "libpq-fe.h"
|
31 | 32 | #include "pqexpbuffer.h"
|
@@ -1392,69 +1393,6 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
|
1392 | 1393 | WriteRecoveryConf();
|
1393 | 1394 | }
|
1394 | 1395 |
|
1395 |
| -/* |
1396 |
| - * Escape a parameter value so that it can be used as part of a libpq |
1397 |
| - * connection string, e.g. in: |
1398 |
| - * |
1399 |
| - * application_name=<value> |
1400 |
| - * |
1401 |
| - * The returned string is malloc'd. Return NULL on out-of-memory. |
1402 |
| - */ |
1403 |
| -static char * |
1404 |
| -escapeConnectionParameter(const char *src) |
1405 |
| -{ |
1406 |
| - bool need_quotes = false; |
1407 |
| - bool need_escaping = false; |
1408 |
| - const char *p; |
1409 |
| - char *dstbuf; |
1410 |
| - char *dst; |
1411 |
| - |
1412 |
| - /* |
1413 |
| - * First check if quoting is needed. Any quote (') or backslash (\) |
1414 |
| - * characters need to be escaped. Parameters are separated by whitespace, |
1415 |
| - * so any string containing whitespace characters need to be quoted. An |
1416 |
| - * empty string is represented by ''. |
1417 |
| - */ |
1418 |
| - if (strchr(src, '\'') != NULL || strchr(src, '\\') != NULL) |
1419 |
| - need_escaping = true; |
1420 |
| - |
1421 |
| - for (p = src; *p; p++) |
1422 |
| - { |
1423 |
| - if (isspace((unsigned char) *p)) |
1424 |
| - { |
1425 |
| - need_quotes = true; |
1426 |
| - break; |
1427 |
| - } |
1428 |
| - } |
1429 |
| - |
1430 |
| - if (*src == '\0') |
1431 |
| - return pg_strdup("''"); |
1432 |
| - |
1433 |
| - if (!need_quotes && !need_escaping) |
1434 |
| - return pg_strdup(src); /* no quoting or escaping needed */ |
1435 |
| - |
1436 |
| - /* |
1437 |
| - * Allocate a buffer large enough for the worst case that all the source |
1438 |
| - * characters need to be escaped, plus quotes. |
1439 |
| - */ |
1440 |
| - dstbuf = pg_malloc(strlen(src) * 2 + 2 + 1); |
1441 |
| - |
1442 |
| - dst = dstbuf; |
1443 |
| - if (need_quotes) |
1444 |
| - *(dst++) = '\''; |
1445 |
| - for (; *src; src++) |
1446 |
| - { |
1447 |
| - if (*src == '\'' || *src == '\\') |
1448 |
| - *(dst++) = '\\'; |
1449 |
| - *(dst++) = *src; |
1450 |
| - } |
1451 |
| - if (need_quotes) |
1452 |
| - *(dst++) = '\''; |
1453 |
| - *dst = '\0'; |
1454 |
| - |
1455 |
| - return dstbuf; |
1456 |
| -} |
1457 |
| - |
1458 | 1396 | /*
|
1459 | 1397 | * Escape a string so that it can be used as a value in a key-value pair
|
1460 | 1398 | * a configuration file.
|
@@ -1523,9 +1461,8 @@ GenerateRecoveryConf(PGconn *conn)
|
1523 | 1461 | * Write "keyword=value" pieces, the value string is escaped and/or
|
1524 | 1462 | * quoted if necessary.
|
1525 | 1463 | */
|
1526 |
| - escaped = escapeConnectionParameter(option->val); |
1527 |
| - appendPQExpBuffer(&conninfo_buf, "%s=%s", option->keyword, escaped); |
1528 |
| - free(escaped); |
| 1464 | + appendPQExpBuffer(&conninfo_buf, "%s=", option->keyword); |
| 1465 | + appendConnStrVal(&conninfo_buf, option->val); |
1529 | 1466 | }
|
1530 | 1467 |
|
1531 | 1468 | /*
|
|
0 commit comments