refactor(tasks): extract filename regex to shared constant
Move the valid filename regex pattern to a shared constant in `app/utils/filename_utils.py` and update both the task logic and security tests to use it. This eliminates duplication and ensures consistency across the codebase. Changes: - Defined `VALID_FILENAME_PATTERN` and `VALID_FILENAME_RE` in `app/utils/filename_utils.py`. - Updated `app/tasks/extract_metadata_with_gpt.py` to use `VALID_FILENAME_RE`. - Updated `tests/test_path_traversal_security.py` to use `VALID_FILENAME_PATTERN`. This refactoring addresses the duplication mentioned in the TODO in `tests/test_path_traversal_security.py`. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -212,9 +212,10 @@ class TestExtractMetadataFilenameValidation:
|
||||
"""Test that invalid filename formats are rejected."""
|
||||
import re
|
||||
|
||||
# Valid pattern from extract_metadata_with_gpt.py
|
||||
# TODO: Consider extracting this to a shared constant to avoid duplication
|
||||
valid_pattern = r"^[\w\-\. ]+$"
|
||||
from app.utils.filename_utils import VALID_FILENAME_PATTERN
|
||||
|
||||
# Valid pattern from app.utils.filename_utils
|
||||
valid_pattern = VALID_FILENAME_PATTERN
|
||||
|
||||
# Test valid filenames
|
||||
valid_filenames = [
|
||||
|
||||
Reference in New Issue
Block a user