From 7235a312abd1a7314f47463e0704da4f48dec166 Mon Sep 17 00:00:00 2001 From: ziajka Date: Thu, 8 Jun 2017 15:23:18 +0200 Subject: [PATCH] Escaping VPCS name in regex #1067 --- gns3server/compute/vpcs/vpcs_vm.py | 3 ++- tests/compute/vpcs/test_vpcs_vm.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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