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

Commit5e9ecbc

Browse files
Merge pull request#153 from postgrespro/fix-set-auto-conf
Fix set_auto_conf with single quotes
2 parents655a386 +1335e51 commit5e9ecbc

File tree

2 files changed

+85
-7
lines changed

2 files changed

+85
-7
lines changed

‎testgres/node.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,23 +1626,31 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}):
16261626

16271627
name,var=line.partition('=')[::2]
16281628
name=name.strip()
1629-
var=var.strip()
1630-
var=var.strip('"')
1631-
var=var.strip("'")
16321629

1633-
#remove options specified in rm_options list
1630+
#Remove options specified in rm_options list
16341631
ifnameinrm_options:
16351632
continue
16361633

16371634
current_options[name]=var
16381635

16391636
foroptioninoptions:
1640-
current_options[option]=options[option]
1637+
asserttype(option)==str# noqa: E721
1638+
assertoption!=""
1639+
assertoption.strip()==option
1640+
1641+
value=options[option]
1642+
valueType=type(value)
1643+
1644+
ifvalueType==str:
1645+
value=__class__._escape_config_value(value)
1646+
elifvalueType==bool:
1647+
value="on"ifvalueelse"off"
1648+
1649+
current_options[option]=value
16411650

16421651
auto_conf=''
16431652
foroptionincurrent_options:
1644-
auto_conf+="{0} = '{1}'\n".format(
1645-
option,current_options[option])
1653+
auto_conf+=option+" = "+str(current_options[option])+"\n"
16461654

16471655
fordirectiveincurrent_directives:
16481656
auto_conf+=directive+"\n"
@@ -1690,6 +1698,30 @@ def _get_bin_path(self, filename):
16901698
bin_path=get_bin_path(filename)
16911699
returnbin_path
16921700

1701+
def_escape_config_value(value):
1702+
asserttype(value)==str# noqa: E721
1703+
1704+
result="'"
1705+
1706+
forchinvalue:
1707+
ifch=="'":
1708+
result+="\\'"
1709+
elifch=="\n":
1710+
result+="\\n"
1711+
elifch=="\r":
1712+
result+="\\r"
1713+
elifch=="\t":
1714+
result+="\\t"
1715+
elifch=="\b":
1716+
result+="\\b"
1717+
elifch=="\\":
1718+
result+="\\\\"
1719+
else:
1720+
result+=ch
1721+
1722+
result+="'"
1723+
returnresult
1724+
16931725

16941726
classNodeApp:
16951727

‎tests/test_simple.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,52 @@ def test_simple_with_bin_dir(self):
10611061
exceptFileNotFoundError:
10621062
pass# Expected error
10631063

1064+
deftest_set_auto_conf(self):
1065+
# elements contain [property id, value, storage value]
1066+
testData= [
1067+
["archive_command",
1068+
"cp '%p'\"/mnt/server/archivedir/%f\"",
1069+
"'cp\\'%p\\'\"/mnt/server/archivedir/%f\""],
1070+
["restore_command",
1071+
'cp "/mnt/server/archivedir/%f"\'%p\'',
1072+
"'cp\"/mnt/server/archivedir/%f\"\\'%p\\''"],
1073+
["log_line_prefix",
1074+
"'\n\r\t\b\\\"",
1075+
"'\\\'\\n\\r\\t\\b\\\\\""],
1076+
["log_connections",
1077+
True,
1078+
"on"],
1079+
["log_disconnections",
1080+
False,
1081+
"off"],
1082+
["autovacuum_max_workers",
1083+
3,
1084+
"3"]
1085+
]
1086+
1087+
withget_new_node()asnode:
1088+
node.init().start()
1089+
1090+
options= {}
1091+
1092+
forxintestData:
1093+
options[x[0]]=x[1]
1094+
1095+
node.set_auto_conf(options)
1096+
node.stop()
1097+
node.slow_start()
1098+
1099+
auto_conf_path=f"{node.data_dir}/postgresql.auto.conf"
1100+
withopen(auto_conf_path,"r")asf:
1101+
content=f.read()
1102+
1103+
forxintestData:
1104+
self.assertIn(
1105+
x[0]+" = "+x[2],
1106+
content,
1107+
x[0]+" stored wrong"
1108+
)
1109+
10641110

10651111
if__name__=='__main__':
10661112
ifos.environ.get('ALT_CONFIG'):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp