Skip to content

Conversation

@john-doe-coding
Copy link

Downloads were crashing when story/highlight names contained characters like :) (e.g., "A_day_in_my_life:)"). SAF doesn't allow these characters, so createDirectory() returns null and we'd get a NullPointerException.

Also fixed a related issue where re-downloading the same file would crash if file_hash_check was disabled, since createFile() returns null for existing files.

Changes:

  • Added sanitizeFileName() that replaces invalid characters (: * ? " < > | / \) with underscores
  • Applied sanitization to both directory and file names
  • Now shows "already downloaded" toast instead of crashing when file exists
  • Replaced !! with proper null checks and descriptive error messages

@rhunk
Copy link
Owner

rhunk commented Jan 20, 2026

I created the file hash check feature so that the findFile function, which is expensive to execute, is not called by default.
But in your PR, the findFile function is executed even if file hash check feature is not enabled. Can you fix this?

- Add sanitizeFileName() to replace invalid SAF characters (: * ? " < > | / \) with underscores
- Fix NullPointerException when createDirectory() or createFile() returns null
- Handle existing files gracefully: show "already downloaded" instead of crashing
- Works regardless of file_hash_check setting
@john-doe-coding john-doe-coding force-pushed the fix/sanitize-download-filenames branch from 474a123 to 2807385 Compare January 21, 2026 15:11
@john-doe-coding
Copy link
Author

@rhunk addressed, let me know if the new approach addresses your concern, or if you'd like to see any other changes.

@rhunk
Copy link
Owner

rhunk commented Jan 21, 2026

I saw that paths are already sanitized in DownloadRequest.kt#L41-L44. There is no need to add a new sanitize function.
If this causes crashes please open an issue with logs because I am unable to reproduce it
Thank you for your contribution

@rhunk rhunk closed this Jan 21, 2026
Repository owner locked as resolved and limited conversation to collaborators Jan 21, 2026
@john-doe-coding john-doe-coding deleted the fix/sanitize-download-filenames branch January 21, 2026 17:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants