Skip to content

feat(utils): add sanitize_filename() for URL-derived filenames#1146

Open
cz-03 wants to merge 1 commit intolangflow-ai:mainfrom
cz-03:patch-1
Open

feat(utils): add sanitize_filename() for URL-derived filenames#1146
cz-03 wants to merge 1 commit intolangflow-ai:mainfrom
cz-03:patch-1

Conversation

@cz-03
Copy link

@cz-03 cz-03 commented Mar 13, 2026

Adds sanitize_filename(url, fallback, max_length) to file_utils.py to safely derive a storable filename from a URL during document ingestion. Decodes percent-encoding, extracts the last path segment, strips query strings and fragments, and removes characters unsafe on Linux, macOS, and Windows. Preserves the file extension when truncating to max_length. Returns a configurable fallback value instead of raising on malformed or empty URLs, consistent with the defensive patterns already used in safe_unlink() and auto_cleanup_tempfile().

Adds `sanitize_filename(url, fallback, max_length)` to `file_utils.py` to safely derive a storable filename from a URL during document ingestion. Decodes percent-encoding, extracts the last path segment, strips query strings and fragments, and removes characters unsafe on Linux, macOS, and Windows. Preserves the file extension when truncating to `max_length`. Returns a configurable `fallback` value instead of raising on malformed or empty URLs, consistent with the defensive patterns already used in `safe_unlink()` and `auto_cleanup_tempfile()`.
@github-actions github-actions bot added community backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) enhancement 🔵 New feature or request labels Mar 13, 2026
@cz-03 cz-03 closed this Mar 13, 2026
@cz-03 cz-03 reopened this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) community enhancement 🔵 New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant