mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-09 13:54:36 -05:00
* fix: truncate filenames by bytes instead of characters to avoid IOException File name too long * add a CHANGELOG.md entry.
50 lines
1.3 KiB
Kotlin
50 lines
1.3 KiB
Kotlin
package suwayomi.tachidesk
|
|
|
|
import xyz.nulldev.androidcompat.util.SafePath
|
|
import kotlin.test.Test
|
|
import kotlin.test.assertEquals
|
|
import kotlin.test.assertTrue
|
|
|
|
class SafePathTest {
|
|
@Test
|
|
fun invalidCharactersAreReplacedAndEdgesAreTrimmed() {
|
|
val input = " .a:b*c?d<e>f|g\\h/i. "
|
|
|
|
val result = SafePath.buildValidFilename(input)
|
|
|
|
assertEquals("a_b_c_d_e_f_g_h_i", result)
|
|
}
|
|
|
|
@Test
|
|
fun emptyAfterTrimReturnsInvalidMarker() {
|
|
assertEquals("(invalid)", SafePath.buildValidFilename(" ... . "))
|
|
}
|
|
|
|
@Test
|
|
fun resultIsTruncatedTo240Characters() {
|
|
val input = "a".repeat(300)
|
|
|
|
val result = SafePath.buildValidFilename(input)
|
|
|
|
assertEquals(240, result.length)
|
|
assertEquals("a".repeat(240), result)
|
|
}
|
|
|
|
@Test
|
|
fun mixed256CharactersCanExceed255Utf8Bytes() {
|
|
val mixed256 =
|
|
buildString {
|
|
repeat(128) {
|
|
append('a')
|
|
append('你')
|
|
}
|
|
}
|
|
|
|
val result = SafePath.buildValidFilename(mixed256)
|
|
|
|
assertEquals(120, result.length)
|
|
assertEquals(mixed256.take(120), result)
|
|
assertEquals(240, result.toByteArray(Charsets.UTF_8).size)
|
|
assertTrue(result.toByteArray(Charsets.UTF_8).size == 240)
|
|
}
|
|
} |