ma1 pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android
Commits:
-
257aa5e5
by hackademix at 2024-09-30T21:41:21+02:00
1 changed file:
Changes:
| ... | ... | @@ -49,6 +49,8 @@ const val MAX_URI_LENGTH = 25000 |
| 49 | 49 | |
| 50 | 50 | private const val FILE_PREFIX = "file://"
|
| 51 | 51 | private const val MAX_VALID_PORT = 65_535
|
| 52 | +private const val SPACE = " "
|
|
| 53 | +private const val UNDERSCORE = "_"
|
|
| 52 | 54 | |
| 53 | 55 | /**
|
| 54 | 56 | * Shortens URLs to be more user friendly.
|
| ... | ... | @@ -303,7 +305,27 @@ fun String.sanitizeFileName(): String { |
| 303 | 305 | file.name.replace("\\.\\.+".toRegex(), ".")
|
| 304 | 306 | } else {
|
| 305 | 307 | file.name.replace(".", "")
|
| 306 | - }
|
|
| 308 | + }.replaceContinuousSpaces()
|
|
| 309 | + .replaceEscapedCharacters()
|
|
| 310 | + .trim()
|
|
| 311 | +}
|
|
| 312 | + |
|
| 313 | + |
|
| 314 | +/**
|
|
| 315 | + * Replaces control characters from ASCII 0 to ASCII 19 with '_' so the file name is valid
|
|
| 316 | + * and is correctly displayed.
|
|
| 317 | + */
|
|
| 318 | +private fun String.replaceEscapedCharacters(): String {
|
|
| 319 | + val escapedCharactersRegex = "[\\x00-\\x13*\"?<>:|\\\\]".toRegex()
|
|
| 320 | + return replace(escapedCharactersRegex, UNDERSCORE)
|
|
| 321 | +}
|
|
| 322 | + |
|
| 323 | +/**
|
|
| 324 | + * Replaces continuous spaces with a single space.
|
|
| 325 | + */
|
|
| 326 | +private fun String.replaceContinuousSpaces(): String {
|
|
| 327 | + val escapedCharactersRegex = "[\\p{Z}\\s]+".toRegex()
|
|
| 328 | + return replace(escapedCharactersRegex, SPACE)
|
|
| 307 | 329 | }
|
| 308 | 330 | |
| 309 | 331 | /**
|