X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParser.kt;h=c97a1fc3dcf6742d17d6a2853f4f8b21da7be770;hb=6ddb4dad913e7b06a5ac5f33f73bf8214049bd8e;hp=b711ca8fdbd760782d702c57640dbbf8ad683647;hpb=f98ec5222b0611a7e473c01cb6ef3a4ef73bc294;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt b/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt index b711ca8..c97a1fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt +++ b/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt @@ -1,7 +1,6 @@ package net.pterodactylus.sone.text import freenet.keys.* -import freenet.support.* import net.pterodactylus.sone.data.* import net.pterodactylus.sone.data.impl.* import net.pterodactylus.sone.database.* @@ -67,13 +66,15 @@ class SoneTextParser @Inject constructor(private val soneProvider: SoneProvider? } SSK, USK -> try { - FreenetURI(linkWithoutBacklink).let { uri -> - uri.allMetaStrings - ?.takeIf { (it.size > 1) || ((it.size == 1) && (it.single() != "")) } - ?.lastOrNull() - ?: uri.docName - ?: "${uri.keyType}@${uri.routingKey.asFreenetBase64}" - }.let { FreenetLinkPart(linkWithoutBacklink.removeSuffix("/"), it, trusted = context?.routingKey?.contentEquals(FreenetURI(linkWithoutBacklink).routingKey) == true) } + FreenetURI(linkWithoutBacklink) + .workaroundForFaultyConstructorInFred1485AndBelow() + .let { uri -> + uri.allMetaStrings + ?.takeIf { (it.size > 1) || ((it.size == 1) && (it.single() != "")) } + ?.lastOrNull() + ?: uri.docName + ?: "${uri.keyType}@${uri.routingKey.asFreenetBase64}" + }.let { FreenetLinkPart(linkWithoutBacklink.removeSuffix("/"), it, trusted = context?.routingKey?.contentEquals(FreenetURI(linkWithoutBacklink).routingKey) == true) } } catch (e: MalformedURLException) { PlainTextPart(linkWithoutBacklink) } @@ -94,6 +95,9 @@ class SoneTextParser @Inject constructor(private val soneProvider: SoneProvider? } +private fun FreenetURI.workaroundForFaultyConstructorInFred1485AndBelow() = + also { if (it.routingKey == null) throw MalformedURLException("SSK/USK without routing key") } + private fun List.mergeMultipleEmptyLines() = fold(emptyList()) { previous, current -> if (previous.isEmpty()) { previous + current