diff --git a/app/src/main/java/com/jerboa/Utils.kt b/app/src/main/java/com/jerboa/Utils.kt index 5c7aa1403..18f40ee42 100644 --- a/app/src/main/java/com/jerboa/Utils.kt +++ b/app/src/main/java/com/jerboa/Utils.kt @@ -498,11 +498,14 @@ fun pictrsImageThumbnail(src: String, thumbnailSize: Int): String { } val host = split[0] + var path = split[1] // eliminate the query param portion of the path so we can replace it later // without this, we'd end up with something like host/path?thumbnail=...?thumbnail=... - val path = split[1].replaceAfter('?', "") + if ("?" in path) { + path = path.replaceAfter('?', "").dropLast(1) + } - return "$host/pictrs/image/${path}thumbnail=$thumbnailSize&format=webp" + return "$host/pictrs/image/$path?thumbnail=$thumbnailSize&format=webp" } fun isImage(url: String): Boolean { diff --git a/app/src/test/java/com/jerboa/UtilsKtTest.kt b/app/src/test/java/com/jerboa/UtilsKtTest.kt index dd06c4690..d3141f467 100644 --- a/app/src/test/java/com/jerboa/UtilsKtTest.kt +++ b/app/src/test/java/com/jerboa/UtilsKtTest.kt @@ -114,6 +114,13 @@ class UtilsKtTest { @Test fun testPictrsImageThumbnail() { assertEquals("invalid", pictrsImageThumbnail("invalid", 3)) + assertEquals( + "http://localhost:8535/pictrs/image/file.png?thumbnail=3&format=webp", + pictrsImageThumbnail( + "http://localhost:8535/pictrs/image/file.png", + 3, + ), + ) assertEquals( "http://localhost:8535/pictrs/image/file.png?thumbnail=3&format=webp", pictrsImageThumbnail(