[Confluence] Sanitize attachment filenames to prevent download failures #1549
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.
Pull Request Description
This PR improves the
download_attachments_from_page
method by adding filename sanitization to handle invalid characters in attachment filenames that can cause download failures on certain file systems.While building a component for Confluence and scraping one of the spaces, I noticed that some files could not be downloaded because their names contained invalid characters (such as
<>:"/\|?*
and control characters) which are not allowed on Windows and other platforms.To address this, the code now replaces these invalid characters with underscores (
_
) to ensure files can be saved without errors. Additionally, a warning is issued to notify users when a filename has been modified due to sanitization.As an example, when running on macOS, I encountered a filename like:
which, after sanitization for Windows compatibility, would be handled gracefully by the refactored code. The refactor aims to be general and platform-agnostic, but focused on preventing errors commonly seen on Windows.
This is my first pull request to a major open-source library, so I welcome any comments, suggestions, or recommendations for improving the implementation or code style. I’m happy to make any necessary adjustments to meet the project’s standards.
Thanks for reading.