From a4b6f610ca0d2cf73ccbc40c5d9d5b1cc9c629b9 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Sat, 6 Dec 2025 23:40:32 -0500 Subject: fix: normalize spaces in profile names w dashes for conf requirements, display actual in FE --- py_modules/lsfg_vk/config_schema.py | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'py_modules/lsfg_vk/config_schema.py') diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py index 3a96401..4ab2dcb 100644 --- a/py_modules/lsfg_vk/config_schema.py +++ b/py_modules/lsfg_vk/config_schema.py @@ -453,20 +453,55 @@ class ConfigurationManager: from .config_schema_generated import create_config_dict return create_config_dict(**kwargs) + @staticmethod + def normalize_profile_name(profile_name: str) -> str: + """Normalize profile name by converting spaces to dashes and trimming + + This allows users to enter names with spaces, which are then safely + converted to dashes for storage and shell script compatibility. + + Args: + profile_name: The raw profile name from user input + + Returns: + Normalized profile name with spaces converted to dashes + """ + if not profile_name: + return profile_name + + # Trim whitespace and convert spaces to dashes + normalized = profile_name.strip().replace(' ', '-') + + # Collapse multiple consecutive dashes into one + while '--' in normalized: + normalized = normalized.replace('--', '-') + + # Remove leading/trailing dashes + normalized = normalized.strip('-') + + return normalized + @staticmethod def validate_profile_name(profile_name: str) -> bool: - """Validate profile name for safety""" + """Validate profile name for safety (after normalization)""" if not profile_name: return False + # Normalize first - this converts spaces to dashes + normalized = ConfigurationManager.normalize_profile_name(profile_name) + + if not normalized: + return False + # Check for invalid characters that could cause issues in shell scripts or TOML - invalid_chars = set(' \t\n\r\'"\\/$|&;()<>{}[]`*?') - if any(char in invalid_chars for char in profile_name): + # Note: spaces are now allowed as input (they get converted to dashes) + invalid_chars = set('\t\n\r\'"\\/$|&;()<>{}[]`*?') + if any(char in invalid_chars for char in normalized): return False # Check for reserved names reserved_names = {'global', 'game', 'current_profile'} - if profile_name.lower() in reserved_names: + if normalized.lower() in reserved_names: return False return True @@ -477,6 +512,9 @@ class ConfigurationManager: if not ConfigurationManager.validate_profile_name(profile_name): raise ValueError(f"Invalid profile name: {profile_name}") + # Normalize the profile name (converts spaces to dashes) + profile_name = ConfigurationManager.normalize_profile_name(profile_name) + if profile_name in profile_data["profiles"]: raise ValueError(f"Profile '{profile_name}' already exists") @@ -533,6 +571,9 @@ class ConfigurationManager: if not ConfigurationManager.validate_profile_name(new_name): raise ValueError(f"Invalid profile name: {new_name}") + # Normalize the new name (converts spaces to dashes) + new_name = ConfigurationManager.normalize_profile_name(new_name) + if old_name not in profile_data["profiles"]: raise ValueError(f"Profile '{old_name}' does not exist") -- cgit v1.2.3