import net.pterodactylus.sone.text.LinkType.SONE
import net.pterodactylus.sone.text.LinkType.SSK
import net.pterodactylus.sone.text.LinkType.USK
-import net.pterodactylus.sone.utils.let
import org.bitpedia.util.Base32
import java.net.MalformedURLException
}
SSK, USK ->
try {
- FreenetLinkPart(link, FreenetURI(link).docName, trusted = context?.routingKey?.contentEquals(FreenetURI(link).routingKey) == true)
+ FreenetURI(link).let { uri ->
+ uri.docName ?: "${uri.keyType}@${uri.routingKey.freenetBase64}"
+ }.let { FreenetLinkPart(link, it, trusted = context?.routingKey?.contentEquals(FreenetURI(link).routingKey) == true) }
} catch (e: MalformedURLException) {
PlainTextPart(link)
}
private val whitespace = Regex("[\\u000a\u0020\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c\u200d\u202f\u205f\u2060\u2800\u3000]")
private data class NextLink(val position: Int, val linkType: LinkType, val link: String, val remainder: String)
+
+private val ByteArray.freenetBase64 get() = Base64.encode(this)!!
}
@Test
+ public void sskWithoutDocumentNameIsParsedCorrectly() {
+ Iterable<Part> parts = soneTextParser.parse(
+ "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8",
+ null);
+ assertThat("Part Text", convertText(parts),
+ is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|"
+ + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|"
+ + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU]"));
+ }
+
+ @Test
public void sskLinkWithoutContextIsNotTrusted() {
Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", null);
assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test]"));