From: David ‘Bombe’ Roden Date: Sun, 18 Oct 2026 08:50:08 +0000 (+0200) Subject: 🐛 Start loading elements with the decomposed & normalized URI X-Git-Tag: v83^2~5^2~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ff0af944389a22af143561d62c1c4d5af4034a8f;p=Sone.git 🐛 Start loading elements with the decomposed & normalized URI --- diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index e87628a..1f3130b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -50,7 +50,7 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke ByteArrayInputStream(data).use { ImageIO.read(it) }?.let { - elementCache.get(uri.toString().decode().normalize()) { + elementCache.get(uri.toString()) { LinkedElement(uri.toString(), properties = mapOf("type" to "image", "size" to data.size, "sizeHuman" to data.size.human)) .apply { logger.fine("Downloaded image from $link: size=${properties["size"]}.") @@ -60,7 +60,7 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke } mimeType.baseType == "text/html" -> { val document = Jsoup.parse(data.toString(Charset.forName(mimeType.getParameter("charset") ?: "UTF-8"))) - elementCache.get(uri.toString().decode().normalize()) { + elementCache.get(uri.toString()) { LinkedElement(uri.toString(), properties = mapOf( "type" to "html", "size" to data.size, "sizeHuman" to data.size.human, "title" to document.title().emptyToNull, @@ -76,14 +76,14 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke } override fun failed(uri: FreenetURI) { - failureCache.put(uri.toString().decode().normalize(), true) + failureCache.put(uri.toString(), true) removeLoadingLink(uri) logger.fine { "Download failed for $uri." } } private fun removeLoadingLink(uri: FreenetURI) { synchronized(loadingLinks) { - loadingLinks.invalidate(uri.toString().decode().normalize()) + loadingLinks.invalidate(uri.toString()) } } } @@ -102,7 +102,7 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke } if (loadingLinks.getIfPresent(normalizedLink) == null) { loadingLinks.put(normalizedLink, true) - freenetInterface.startFetch(FreenetURI(link), callback) + freenetInterface.startFetch(FreenetURI(normalizedLink), callback) } } return LinkedElement(link, loading = true) diff --git a/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt index ad53ad0..58ad8fd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/DefaultElementLoaderTest.kt @@ -310,6 +310,13 @@ class DefaultElementLoaderTest { } } + @Test + fun `element loader decodes and normalizes link`() { + runWithCallback(decomposedKey) { _, _, _, fetchedUris -> + assertThat(fetchedUris(), contains(FreenetURI(normalizedKey))) + } + } + private fun read(resource: String): ByteArray = javaClass.getResourceAsStream(resource)?.use { input -> ByteArrayOutputStream().use {