diff --git a/gns3server/compute/vpcs/vpcs_vm.py b/gns3server/compute/vpcs/vpcs_vm.py index 0c8c9ebc..6b6629bf 100644 --- a/gns3server/compute/vpcs/vpcs_vm.py +++ b/gns3server/compute/vpcs/vpcs_vm.py @@ -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) diff --git a/tests/compute/vpcs/test_vpcs_vm.py b/tests/compute/vpcs/test_vpcs_vm.py index b36ac1c9..e08f537f 100644 --- a/tests/compute/vpcs/test_vpcs_vm.py +++ b/tests/compute/vpcs/test_vpcs_vm.py @@ -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