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

Commit1b9a293

Browse files
author
vshepard
committed
Fix set_auto_conf with single quotes
1 parent655a386 commit1b9a293

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

‎testgres/node.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,17 +1627,22 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}):
16271627
name,var=line.partition('=')[::2]
16281628
name=name.strip()
16291629
var=var.strip()
1630-
var=var.strip('"')
1631-
var=var.strip("'")
16321630

1633-
# remove options specified in rm_options list
1631+
# Handle quoted values and remove escaping
1632+
ifvar.startswith("'")andvar.endswith("'"):
1633+
var=var[1:-1].replace("''","'")
1634+
1635+
# Remove options specified in rm_options list
16341636
ifnameinrm_options:
16351637
continue
16361638

16371639
current_options[name]=var
16381640

16391641
foroptioninoptions:
1640-
current_options[option]=options[option]
1642+
value=options[option]
1643+
ifisinstance(value,str):
1644+
value=value.replace("'","\\'")
1645+
current_options[option]=value
16411646

16421647
auto_conf=''
16431648
foroptionincurrent_options:

‎tests/test_simple.py

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

1064+
deftest_set_auto_conf(self):
1065+
withget_new_node()asnode:
1066+
node.init().start()
1067+
1068+
options= {
1069+
"archive_command":"cp '%p'\"/mnt/server/archivedir/%f\"",
1070+
'restore_command':'cp "/mnt/server/archivedir/%f"\'%p\'',
1071+
}
1072+
1073+
node.set_auto_conf(options)
1074+
node.stop()
1075+
node.slow_start()
1076+
1077+
auto_conf_path=f"{node.data_dir}/postgresql.auto.conf"
1078+
withopen(auto_conf_path,"r")asf:
1079+
content=f.read()
1080+
self.assertIn(
1081+
"archive_command = 'cp\\'%p\\'\"/mnt/server/archivedir/%f\"",
1082+
content,
1083+
"archive_command stored wrong"
1084+
)
1085+
self.assertIn(
1086+
"restore_command = 'cp\"/mnt/server/archivedir/%f\"\\'%p\\''",
1087+
content,
1088+
"restore_command stored wrong"
1089+
)
1090+
1091+
10641092

10651093
if__name__=='__main__':
10661094
ifos.environ.get('ALT_CONFIG'):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp