1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-03-09 02:07:55 +01:00

fix: sanitize name space util for bec connector and ads

This commit is contained in:
2026-01-13 11:32:19 +01:00
committed by Jan Wyzula
parent 3cc469a3d1
commit e94ce73950
5 changed files with 33 additions and 21 deletions

View File

@@ -16,6 +16,7 @@ from qtpy.QtWidgets import QApplication
from bec_widgets.cli.rpc.rpc_register import RPCRegister
from bec_widgets.utils.error_popups import ErrorPopupUtility, SafeSlot
from bec_widgets.utils.name_utils import sanitize_namespace
from bec_widgets.utils.widget_io import WidgetHierarchy
from bec_widgets.utils.yaml_dialog import load_yaml, load_yaml_gui, save_yaml, save_yaml_gui
@@ -102,6 +103,8 @@ class BECConnector:
"""
# Extract object_name from kwargs to not pass it to Qt class
object_name = object_name or kwargs.pop("objectName", None)
if object_name is not None:
object_name = sanitize_namespace(object_name)
# Ensure the parent is always the first argument for QObject
parent = kwargs.pop("parent", None)
# This initializes the QObject or any qt related class BECConnector has to be used from this line down with QObject, otherwise hierarchy logic will not work

View File

@@ -14,3 +14,22 @@ def pascal_to_snake(name: str) -> str:
s1 = re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name)
s2 = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", s1)
return s2.lower()
def sanitize_namespace(namespace: str | None) -> str | None:
"""
Clean user-provided namespace labels for filesystem compatibility.
Args:
namespace (str | None): Arbitrary namespace identifier supplied by the caller.
Returns:
str | None: Sanitized namespace containing only safe characters, or ``None``
when the input is empty.
"""
if not namespace:
return None
ns = namespace.strip()
if not ns:
return None
return re.sub(r"[^0-9A-Za-z._-]+", "_", ns)