Skip to content

Commit

Permalink
Fix bug with pictrs url query param rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
beatgammit committed Jun 18, 2023
1 parent 145d04a commit ff3d933
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions app/src/test/java/com/jerboa/UtilsKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ff3d933

Please sign in to comment.