Fix(utils): Robustly handle filenames with colons on Windows #718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #717
On the Windows operating system, downloads would fail for any file containing a colon (
:) in its name. This was caused by a two-part bug that manifested in either aValueErroror aWinError 3.Root Cause:
utils.sanitize_filepathfunction usedos.path.basename, which incorrectly interpreted a colon in a simple filename as a drive separator on Windows. This caused the sanitization to fail silently.files.downloadmethod. The security check in this method would correctly reject the malformed path, leading to the crash.This PR introduces a comprehensive fix:
utils.py: Thesanitize_filepathfunction has been completely rewritten to be more robust. It now correctly handles simple filenames by first checking for the absence of path separators, and usesrsplit()to reliably parse full paths. This ensures correct behavior on all platforms without relying on the problematicos.pathfunctions.files.py: The security check within thedownloadmethod has been refactored to a more explicit and reliablepathlibpattern. It now establishes a trusted absolute base directory first, then safely joins the sanitized filename before validation. This change improves security and prevents subtle path resolution bugs.tests/test_utils.py:test_get_file_size) has been fixed by updating a hardcoded value.test_sanitize_filepathtest has been made platform-aware using mocks to ensure it passes on both Windows and POSIX systems.