Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring file and directory handling #5

Merged
merged 4 commits into from
Dec 13, 2023
Merged

Conversation

guiparpinelli
Copy link
Contributor

  1. Pathlib Integration: The use of os module is replaced with Python's more modern pathlib module across various tools. This shift enhances readability and consistency in handling file paths.

  2. Field Validation Enhancements:

    • A new field validator, check_directory_traversal, is implemented to prevent directory traversal attacks. It ensures the provided paths are within allowed directories.
    • The start_directory fields in both BuildDirectoryTree and PrintAllFilesInDirectory classes now use Path instead of str, ensuring better path handling.
  3. Refactoring File Extensions Handling:

    • File extensions are now handled using a set (set[str]) instead of a list (list[str] | None). This change simplifies the logic for including file types in the output.
  4. Improved Directory Traversal:

    • BuildDirectoryTree and PrintAllFilesInDirectory classes have been refactored to use recursive functions for directory traversal, enhancing their efficiency and readability.
  5. Testing Adjustments:

    • Tests have been updated to reflect the changes in the implementation, particularly the use of pathlib and the new field validations.
    • A new test file, test_utils.py, is added to specifically test the check_directory_traversal function.

@guiparpinelli guiparpinelli requested a review from bonk1t December 13, 2023 00:25
@bonk1t bonk1t merged commit 6129357 into main Dec 13, 2023
1 check passed
@guiparpinelli guiparpinelli deleted the fix/dont-allow-dir-traversal branch December 13, 2023 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants