Skip to content

Commit 055bfbd

Browse files
authored
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 <[email protected]> * Update CHANGELOG.md Co-authored-by: Naveen Singh <[email protected]> * Update CHANGELOG.md Co-authored-by: Naveen Singh <[email protected]> --------- Co-authored-by: Jan Guegel <[email protected]> Co-authored-by: Naveen Singh <[email protected]> Refs: #250
1 parent ceb7a5f commit 055bfbd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Fixed
99
- Fixed folders showing up incorrectly as files in copy/move dialog ([#267])
10+
- Fixed error when saving files with unsupported characters ([#250])
1011

1112
## [1.2.3] - 2025-09-15
1213
### Fixed
@@ -74,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7475
[#176]: https://github.com/FossifyOrg/File-Manager/issues/176
7576
[#251]: https://github.com/FossifyOrg/File-Manager/issues/251
7677
[#267]: https://github.com/FossifyOrg/File-Manager/issues/267
78+
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
7779

7880
[Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD
7981
[1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ class SaveAsActivity : SimpleActivity() {
3636
}
3737

3838
val source = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)!!
39-
val filename = getFilenameFromContentUri(source)
39+
val originalFilename = getFilenameFromContentUri(source)
4040
?: source.toString().getFilenameFromPath()
41+
val filename = sanitizeFilename(originalFilename)
4142
val mimeType = contentResolver.getType(source)
4243
?: intent.type?.takeIf { it != "*/*" }
4344
?: filename.getMimeType()
@@ -66,4 +67,9 @@ class SaveAsActivity : SimpleActivity() {
6667
super.onResume()
6768
setupToolbar(binding.activitySaveAsToolbar, NavigationIcon.Arrow)
6869
}
70+
71+
private fun sanitizeFilename(filename: String): String {
72+
return filename.replace("[/\\\\<>:\"|?*\u0000-\u001F]".toRegex(), "_")
73+
.takeIf { it.isNotBlank() } ?: "unnamed_file"
74+
}
6975
}

0 commit comments

Comments
 (0)