test: cover ~5KB nowhere-link fragments end-to-end through the parser

This commit is contained in:
Claude
2026-05-16 21:01:53 +00:00
parent 318e4250de
commit a1e37109c3
@@ -4420,6 +4420,23 @@ class RichTextParserTest {
assertEquals("m", nowhere?.tool)
}
@Test
fun testNowhereLinkWithLargeBase64UrlFragment() {
// Real nowhere links can be kilobytes long (a full store catalogue or forum thread
// base64url-encoded). Verify both UrlDetector capture and our classifier survive a
// ~5KB fragment containing every base64url-legal character (A-Z, a-z, 0-9, -, _).
val alphabet = ('A'..'Z').joinToString("") + ('a'..'z').joinToString("") + ('0'..'9').joinToString("") + "-_"
val payload = (0 until 80).joinToString("") { alphabet }
val url = "https://nowhr.xyz/s#$payload"
val text = "look at this big store $url and reply"
val state = RichTextParser().parseText(text, EmptyTagList, null)
val nowhere = state.paragraphs.flatMap { it.words }.firstOrNull { it is NowhereLinkSegment } as? NowhereLinkSegment
assertEquals(url, nowhere?.segmentText)
assertEquals(payload.length, nowhere?.segmentText?.substringAfter('#')?.length)
assertEquals("nowhr.xyz", nowhere?.host)
assertEquals("s", nowhere?.tool)
}
@Test
fun testPlainNowhereHostWithoutFragmentStaysAsLink() {
// No fragment => not a nowhere site, fall through to LinkSegment.