diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a069d62..32d11b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Fixed folders showing up incorrectly as files in copy/move dialog ([#267]) +- Fixed error when saving files with unsupported characters ([#250]) ## [1.2.3] - 2025-09-15 ### Fixed @@ -74,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#176]: https://github.com/FossifyOrg/File-Manager/issues/176 [#251]: https://github.com/FossifyOrg/File-Manager/issues/251 [#267]: https://github.com/FossifyOrg/File-Manager/issues/267 +[#250]: https://github.com/FossifyOrg/File-Manager/issues/250 [Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD [1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3 diff --git a/app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt b/app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt index 0ee0afb8..cd08f527 100644 --- a/app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt +++ b/app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt @@ -36,8 +36,9 @@ class SaveAsActivity : SimpleActivity() { } val source = intent.getParcelableExtra(Intent.EXTRA_STREAM)!! - val filename = getFilenameFromContentUri(source) + val originalFilename = getFilenameFromContentUri(source) ?: source.toString().getFilenameFromPath() + val filename = sanitizeFilename(originalFilename) val mimeType = contentResolver.getType(source) ?: intent.type?.takeIf { it != "*/*" } ?: filename.getMimeType() @@ -66,4 +67,9 @@ class SaveAsActivity : SimpleActivity() { super.onResume() setupToolbar(binding.activitySaveAsToolbar, NavigationIcon.Arrow) } + + private fun sanitizeFilename(filename: String): String { + return filename.replace("[/\\\\<>:\"|?*\u0000-\u001F]".toRegex(), "_") + .takeIf { it.isNotBlank() } ?: "unnamed_file" + } }