}
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)
}
}
+private fun FreenetURI.workaroundForFaultyConstructorInFred1485AndBelow() =
+ also { if (it.routingKey == null) throw MalformedURLException("SSK/USK without routing key") }
+
private fun List<String>.mergeMultipleEmptyLines() = fold(emptyList<String>()) { previous, current ->
if (previous.isEmpty()) {
previous + current
package net.pterodactylus.sone.text
import com.google.inject.Guice.*
+import freenet.keys.FreenetURI
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.database.*
}
@Test
+ fun `broken usk links is parsed as plain text`() {
+ val context = SoneTextParserContext(IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"))
+ val parts = soneTextParser.parse("USK@/someCrazyName.R1/0", context)
+ FreenetURI("USK@/someCrazyName.R1/0")
+ assertThat("Part Text", convertText(parts), equalTo("USK@/someCrazyName.R1/0"))
+ }
+
+ @Test
fun `test basic ksk links`() {
val parts: Iterable<Part> = soneTextParser.parse("KSK@gpl.txt", null)
assertThat("Part Text", convertText(parts, FreenetLinkPart::class.java), equalTo("[KSK@gpl.txt|KSK@gpl.txt|gpl.txt]"))