Merge pull request 'fix: share-residence import preview polish (closes #7)' (#9) from fix/7-share-residence-import-polish into master
Android UI Tests / ui-tests (push) Has been cancelled
Android UI Tests / ui-tests (push) Has been cancelled
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
@@ -59,12 +59,29 @@ object HoneyDueShareCodec {
|
||||
|
||||
/**
|
||||
* Build a filesystem-safe package filename with `.honeydue` extension.
|
||||
*
|
||||
* Strips only the characters that are actually unsafe on iOS / Android
|
||||
* filesystems (`/`, `\`, `:`, `*`, `?`, `"`, `<`, `>`, `|`, control
|
||||
* chars). Spaces and apostrophes are kept intact so the recipient sees
|
||||
* the original residence / contractor name in the iOS QuickLook title
|
||||
* bar — gitea#7 called out the previous behaviour rendering
|
||||
* "The_Tartt's" instead of "The Tartt's". Internal whitespace is
|
||||
* collapsed to single spaces and trimmed; falls back to "honeyDue" if
|
||||
* the input is blank after sanitising.
|
||||
*/
|
||||
fun safeShareFileName(displayName: String): String {
|
||||
val safeName = displayName
|
||||
.replace(" ", "_")
|
||||
.replace("/", "-")
|
||||
// Keep whitespace through the filter so adjacent space+tab
|
||||
// sequences survive to the regex-collapse step below. Drop
|
||||
// only non-whitespace control chars (NUL etc.) plus the
|
||||
// explicit filesystem-unsafe set.
|
||||
.filter { it !in UNSAFE_FILENAME_CHARS && (it.isWhitespace() || !it.isISOControl()) }
|
||||
.replace(Regex("\\s+"), " ")
|
||||
.trim()
|
||||
.take(50)
|
||||
.ifBlank { "honeyDue" }
|
||||
return "$safeName.honeydue"
|
||||
}
|
||||
|
||||
private val UNSAFE_FILENAME_CHARS = setOf('/', '\\', ':', '*', '?', '"', '<', '>', '|')
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user