summaryrefslogtreecommitdiff
path: root/py_modules/lsfg_vk/config_schema.py
diff options
context:
space:
mode:
authorKurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>2025-12-06 23:52:24 -0500
committerGitHub <noreply@github.com>2025-12-06 23:52:24 -0500
commit97a70cd68813f2174fe145ee79784e509d11a742 (patch)
tree4176c752516ebdb7a4a8841dbe29adee7d6c5774 /py_modules/lsfg_vk/config_schema.py
parent56c493184fc3960e3b33aa789fad618962c339ae (diff)
parenta9c560d66f55e96f1143ad3a310fac8148c0cdd6 (diff)
downloaddecky-lsfg-vk-97a70cd68813f2174fe145ee79784e509d11a742.tar.gz
decky-lsfg-vk-97a70cd68813f2174fe145ee79784e509d11a742.zip
Merge pull request #201 from xXJSONDeruloXx/profile-normalizeHEADmain
fix: normalize spaces in profile names w dashes for conf requirements…
Diffstat (limited to 'py_modules/lsfg_vk/config_schema.py')
-rw-r--r--py_modules/lsfg_vk/config_schema.py49
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")