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=24b04faa3028db2e0f217fb6dc4fa22deda0671f;hpb=5c5bee980f9cab5792e34d1c9840f73b8b191830;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 24b04fa..c97a1fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt +++ b/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt @@ -66,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) } @@ -93,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