From: David ‘Bombe’ Roden Date: Sat, 18 Jul 2026 13:14:56 +0000 (+0200) Subject: 🐛 Let colons be part of links, too X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ad32ec4028fc9efc09302136ab70c1fe740d9b83;p=Sone.git 🐛 Let colons be part of links, too --- diff --git a/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt b/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt index 88e4a03..f1cd50f 100644 --- a/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt +++ b/src/main/kotlin/net/pterodactylus/sone/text/SoneTextParser.kt @@ -201,9 +201,9 @@ private enum class LinkType(private val scheme: String, private val freenetLink: } -private val punctuationChars = listOf('.', ',', '?', '!') +private val punctuationChars = listOf('.', ',', '?', '!', ':') private fun isPunctuation(char: Char) = char in punctuationChars -private val nonLinkCharacters = 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 val nonLinkCharacters = 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) diff --git a/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt index 62418ab..1fe49b1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt @@ -330,9 +330,9 @@ class SoneTextParserTest { } @Test - fun `colon is not considered to be a part of the link`() { + fun `colon is considered to be a part of the link`() { val parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def):foo.jpg) – nice!", null) - assertThat("Part Text", convertText(parts, PlainTextPart::class.java, LinkPart::class.java), equalTo("Some text (and a link: [http://example.sone/abc_(def)|http://example.sone/abc_(def)|example.sone/abc_(def)]:foo.jpg) – nice!")) + assertThat("Part Text", convertText(parts, PlainTextPart::class.java, LinkPart::class.java), equalTo("Some text (and a link: [http://example.sone/abc_(def):foo.jpg|http://example.sone/abc_(def):foo.jpg|example.sone/abc_(def):foo.jpg]) – nice!")) } @Test @@ -342,6 +342,12 @@ class SoneTextParserTest { } @Test + fun `colon is ignored at end of link before whitespace`() { + val parts = soneTextParser.parse("Some text and a link: http://example.sone/abc: Nice!", null) + assertThat("Part Text", convertText(parts, PlainTextPart::class.java, LinkPart::class.java), equalTo("Some text and a link: [http://example.sone/abc|http://example.sone/abc|example.sone/abc]: Nice!")) + } + + @Test fun `multiple punctuation characters are ignored at end of link before whitespace`() { val parts = soneTextParser.parse("Some text and a link: http://example.sone/abc... Nice!", null) assertThat("Part Text", convertText(parts, PlainTextPart::class.java, LinkPart::class.java), equalTo("Some text and a link: [http://example.sone/abc|http://example.sone/abc|example.sone/abc]... Nice!"))