fix: sanitize filenames before saving (#270)

* Fix "Replace characters on save as function, FileNotFoundException" #250

* Update CHANGELOG.md

update changelog

* Update app/src/main/kotlin/org/fossify/filemanager/activities/SaveAsActivity.kt

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

---------

Co-authored-by: Jan Guegel <jan@guegel.eu>
Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

Refs: https://github.com/FossifyOrg/File-Manager/issues/250
This commit is contained in:
Jan
2025-09-26 08:58:58 +02:00
committed by GitHub
parent ceb7a5f2a2
commit 055bfbd3b8
2 changed files with 9 additions and 1 deletions

View File

@@ -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

View File

@@ -36,8 +36,9 @@ class SaveAsActivity : SimpleActivity() {
}
val source = intent.getParcelableExtra<Uri>(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"
}
}