From bd443071873bcd6926ba0cfe5c5503b9e6793152 Mon Sep 17 00:00:00 2001 From: AdenAthar Date: Thu, 11 Sep 2025 14:11:27 -0700 Subject: [PATCH] Fix FileDirValue to validate input before setting value - Add input validation before assigning to self.value - Validate that input is a string and not empty - Only set self.value after successful directory creation and validation - Addresses requirement to validate all values before they get set --- Granny/Models/Values/FileDirValue.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Granny/Models/Values/FileDirValue.py b/Granny/Models/Values/FileDirValue.py index 39e8f5b..ce573b2 100644 --- a/Granny/Models/Values/FileDirValue.py +++ b/Granny/Models/Values/FileDirValue.py @@ -25,10 +25,20 @@ def setValue(self, value: str): Raises: ValueError: If the path is not a valid directory after assignment. """ - self.value = value - if not self.validate(): + # Validate input before setting + if not isinstance(value, str): + raise ValueError(f"Directory path must be a string, got {type(value)}") + if not value.strip(): + raise ValueError("Directory path cannot be empty") + + # Create directory first, then set and validate + os.makedirs(value, exist_ok=True) + + # Only set the value after successful directory creation and validation + if os.path.isdir(value): + self.value = value + else: raise ValueError("Not a directory. Please specify a directory.") - os.makedirs(self.value, exist_ok=True) def validate(self) -> bool: """