From ff0af944389a22af143561d62c1c4d5af4034a8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 18 Oct 2026 10:50:08 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Start=20loading=20elements=20with?= =?utf8?q?=20the=20decomposed=20&=20normalized=20URI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt | 10 +++++----- .../net/pterodactylus/sone/core/DefaultElementLoaderTest.kt | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) 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 { -- 2.7.4