From 4ef2caddf5198cc10c04926c8289cd445d10c426 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 28 Oct 2016 13:24:57 +0200 Subject: [PATCH 1/3] Remove debug prints Oops. Contributes to issue CURA-2692. --- cura/Settings/MachineNameValidator.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/cura/Settings/MachineNameValidator.py b/cura/Settings/MachineNameValidator.py index d859e85343..c4cab243c3 100644 --- a/cura/Settings/MachineNameValidator.py +++ b/cura/Settings/MachineNameValidator.py @@ -56,14 +56,11 @@ class MachineNameValidator(QObject): def updateValidation(self, new_name): is_valid = self.validate(new_name, 0) if is_valid == QValidator.Acceptable: - print("VALID") self.validation_regex = "^.*$" #Matches anything. else: - print("BROKEN!") self.validation_regex = "a^" #Never matches (unless you manage to get "a" before the start of the string... good luck). self.validationChanged.emit() @pyqtProperty("QRegExp", notify=validationChanged) def machineNameRegex(self): - print(self.machine_name_regex) return QRegExp(self.machine_name_regex) \ No newline at end of file From d33f6d2e44da83a4a3e655b847b835edf4e55964 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 28 Oct 2016 13:32:49 +0200 Subject: [PATCH 2/3] Make regex match exactly on entire string The carot indicates start of string, the dollar the end of string. So it must match on the entire string, not a piece of it. Contributes to issue CURA-2692. --- cura/Settings/MachineNameValidator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/Settings/MachineNameValidator.py b/cura/Settings/MachineNameValidator.py index c4cab243c3..34b6351144 100644 --- a/cura/Settings/MachineNameValidator.py +++ b/cura/Settings/MachineNameValidator.py @@ -28,7 +28,7 @@ class MachineNameValidator(QObject): # special character, and that up to [machine_name_max_length / 12] times. maximum_special_characters = int(machine_name_max_length / 12) unescaped = r"[a-zA-Z0-9_\-\.\/]" - self.machine_name_regex = r"((" + unescaped + "){0,12}|.){0," + str(maximum_special_characters) + r"}" + self.machine_name_regex = r"^((" + unescaped + "){0,12}|.){0," + str(maximum_special_characters) + r"}$" validationChanged = pyqtSignal() From 9f43a740a6a3146d32ef1684a69fa34a3c5a0f87 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 28 Oct 2016 13:33:26 +0200 Subject: [PATCH 3/3] Also validate machine name in rename dialogue Otherwise you could still circumvent the length limitation. Contributes to issue CURA-2692. --- resources/qml/Preferences/MachinesPage.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/qml/Preferences/MachinesPage.qml b/resources/qml/Preferences/MachinesPage.qml index 78553bb37f..e6ddef7979 100644 --- a/resources/qml/Preferences/MachinesPage.qml +++ b/resources/qml/Preferences/MachinesPage.qml @@ -251,6 +251,8 @@ UM.ManagementPage { id: renameDialog; object: base.currentItem && base.currentItem.name ? base.currentItem.name : ""; + property var machine_name_validator: Cura.MachineNameValidator { } + validName: renameDialog.newName.match(renameDialog.machine_name_validator.machineNameRegex) != null; onAccepted: { Cura.MachineManager.renameMachine(base.currentItem.id, newName.trim());