diff options
| author | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-12-06 23:40:32 -0500 |
|---|---|---|
| committer | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-12-06 23:40:32 -0500 |
| commit | a4b6f610ca0d2cf73ccbc40c5d9d5b1cc9c629b9 (patch) | |
| tree | d2bc9dc5838ff2f8d8032c12c6cb7ba927155589 /py_modules/lsfg_vk/config_schema.py | |
| parent | 56c493184fc3960e3b33aa789fad618962c339ae (diff) | |
| download | decky-lsfg-vk-a4b6f610ca0d2cf73ccbc40c5d9d5b1cc9c629b9.tar.gz decky-lsfg-vk-a4b6f610ca0d2cf73ccbc40c5d9d5b1cc9c629b9.zip | |
fix: normalize spaces in profile names w dashes for conf requirements, display actual in FE
Diffstat (limited to 'py_modules/lsfg_vk/config_schema.py')
| -rw-r--r-- | py_modules/lsfg_vk/config_schema.py | 49 |
1 files changed, 45 insertions, 4 deletions
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 @@ -454,19 +454,54 @@ class ConfigurationManager: 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") |
