Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2953cd6

Browse files
committed
Only quote libpq connection string values that need quoting.
There's no harm in excessive quoting per se, but it makes the strings nicerto read. The values can get quite unwieldy, when they're first quoted withinwithin single-quotes when included in the connection string, and then allthe single-quotes are escaped when the connection string is passed as ashell argument.
1 parent3dee636 commit2953cd6

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,15 +2038,40 @@ dumpTimestamp(char *msg)
20382038
staticvoid
20392039
doConnStrQuoting(PQExpBufferbuf,constchar*str)
20402040
{
2041-
while (*str)
2041+
constchar*s;
2042+
boolneedquotes;
2043+
2044+
/*
2045+
* If the string consists entirely of plain ASCII characters, no need to
2046+
* quote it. This is quite conservative, but better safe than sorry.
2047+
*/
2048+
needquotes= false;
2049+
for (s=str;*s;s++)
2050+
{
2051+
if (!((*s >='a'&&*s <='z')|| (*s >='A'&&*s <='Z')||
2052+
(*s >='0'&&*s <='9')||*s=='_'||*s=='.'))
2053+
{
2054+
needquotes= true;
2055+
break;
2056+
}
2057+
}
2058+
2059+
if (needquotes)
20422060
{
2043-
/* ' and \ must be escaped by to \' and \\ */
2044-
if (*str=='\''||*str=='\\')
2045-
appendPQExpBufferChar(buf,'\\');
2061+
appendPQExpBufferChar(buf,'\'');
2062+
while (*str)
2063+
{
2064+
/* ' and \ must be escaped by to \' and \\ */
2065+
if (*str=='\''||*str=='\\')
2066+
appendPQExpBufferChar(buf,'\\');
20462067

2047-
appendPQExpBufferChar(buf,*str);
2048-
str++;
2068+
appendPQExpBufferChar(buf,*str);
2069+
str++;
2070+
}
2071+
appendPQExpBufferChar(buf,'\'');
20492072
}
2073+
else
2074+
appendPQExpBufferStr(buf,str);
20502075
}
20512076

20522077
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp