1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Escaping VPCS name in regex #1067

This commit is contained in:
ziajka 2017-06-08 15:23:18 +02:00 committed by Julien Duponchelle
parent 40cc5d76b3
commit 7235a312ab
2 changed files with 8 additions and 1 deletions

View File

@ -171,7 +171,8 @@ class VPCSVM(BaseNode):
if self.script_file:
content = self.startup_script
content = content.replace(self._name, new_name)
content = re.sub(r"^set pcname .+$", "set pcname " + new_name, content, flags=re.MULTILINE)
escaped_name = re.escape(new_name)
content = re.sub(r"^set pcname .+$", "set pcname " + escaped_name, content, flags=re.MULTILINE)
self.startup_script = content
super(VPCSVM, VPCSVM).name.__set__(self, new_name)

View File

@ -251,6 +251,12 @@ def test_update_startup_script_h(vm):
assert f.read() == "set pcname pc1\n"
def test_update_startup_script_with_escaping_characters_in_name(vm):
vm.startup_script = "set pcname initial-name\n"
vm.name = "test\\"
assert vm.startup_script == "set pcname test\\\n"
def test_get_startup_script(vm):
content = "echo GNS3 VPCS\nip 192.168.1.2"
vm.startup_script = content