Prevent using reserved names for properties or aliases (Fix #16846) (#16902)

* Prevent naming properties with reserved words (Fix #16846)

* Prevent using reserved constant names for properties or aliases

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* App: Add unit test for isTokenAConstant

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
Kris Wilk
2024-10-03 11:03:10 -04:00
committed by GitHub
parent 69b4a6429e
commit ffa1189634
7 changed files with 48 additions and 2 deletions

View File

@@ -30,6 +30,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/ExpressionParser.h>
#include <App/PropertyUnits.h>
#include <Base/Tools.h>
@@ -351,6 +352,14 @@ void DlgAddPropertyVarSet::checkName() {
throw CreatePropertyException("Invalid name");
}
if(App::ExpressionParser::isTokenAUnit(name) || App::ExpressionParser::isTokenAConstant(name)) {
QMessageBox::critical(getMainWindow(),
QObject::tr("Invalid name"),
QObject::tr("The property name is a reserved word."));
clearEditors(!CLEAR_NAME);
throw CreatePropertyException("Invalid name");
}
if (namePropertyToAdd.empty()) {
// we are adding a new property, check whether it doesn't already exist
auto prop = varSet->getPropertyByName(name.c_str());