From 7c2962e11950fbbcd45408d0db545abeeaf529bf Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 17 Feb 2021 17:59:25 -0600 Subject: [PATCH] Fix unit test with property name sanitize. --- src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui | 2 +- src/Mod/Path/PathScripts/PathPropertyBag.py | 5 ++++- src/Mod/Path/PathScripts/PathPropertyBagGui.py | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui index c65c02ea82..38a4b3057f 100644 --- a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui +++ b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui @@ -24,7 +24,7 @@ - <html><head/><body><p>Name of property.</p></body></html> + <html><head/><body><p>Name of property. Can only contain letters, numbers, and underscores. MixedCase names will display with spaces &quot;Mixed Case&quot;</p></body></html> diff --git a/src/Mod/Path/PathScripts/PathPropertyBag.py b/src/Mod/Path/PathScripts/PathPropertyBag.py index eefee2ed30..2142457ed1 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBag.py +++ b/src/Mod/Path/PathScripts/PathPropertyBag.py @@ -22,6 +22,7 @@ import FreeCAD import PySide +import re __title__ = 'Generic property container to store some values.' __author__ = 'sliptonic (Brad Collette)' @@ -70,7 +71,7 @@ class PropertyBag(object): def __sanitizePropertyName(self, name): if(len(name) == 0): return - clean = name[0].lower() + clean = name[0] for i in range(1, len(name)): if (name[i] == ' '): clean += name[i + 1].upper() @@ -96,6 +97,8 @@ class PropertyBag(object): groups = self.obj.CustomPropertyGroups name = self.__sanitizePropertyName(name) + if not re.match("^[A-Za-z0-9_]*$", name): + raise ValueError('Property Name can only contain letters and numbers') if not group in groups: groups.append(group) diff --git a/src/Mod/Path/PathScripts/PathPropertyBagGui.py b/src/Mod/Path/PathScripts/PathPropertyBagGui.py index a0e1b03fb4..7446379b53 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBagGui.py +++ b/src/Mod/Path/PathScripts/PathPropertyBagGui.py @@ -22,12 +22,13 @@ import FreeCAD import FreeCADGui -import PathGui +#import PathGui import PathScripts.PathIconViewProvider as PathIconViewProvider import PathScripts.PathLog as PathLog import PathScripts.PathPropertyBag as PathPropertyBag import PathScripts.PathPropertyEditor as PathPropertyEditor import PathScripts.PathUtil as PathUtil +import re from PySide import QtCore, QtGui @@ -153,6 +154,7 @@ class PropertyCreate(object): self.form.propertyEnum.textChanged.connect(self.updateUI) def updateUI(self): + typeSet = True if self.propertyIsEnumeration(): self.form.labelEnum.setEnabled(True) @@ -166,7 +168,10 @@ class PropertyCreate(object): ok = self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok) - if typeSet and self.propertyName() and self.propertyGroup(): + if not re.match("^[A-Za-z0-9_]*$", self.form.propertyName.text()): + typeSet = False + + if typeSet and self.propertyGroup(): ok.setEnabled(True) else: ok.setEnabled(False)