test: add regression tests for PR #1907 URL crash fix

Tests cover the StringIndexOutOfBoundsException in Url.getPart() that
occurred when readEnd() trimmed trailing characters (e.g. ':') from a
detected URL but urlMarker indices remained pointing past the trimmed
string's end.

- UrlMarkerTest: three cases testing PORT/QUERY index at or beyond
  string length (the boundary conditions fixed by minOf clamping and
  the startIndex >= length guard)
- UrlsDetectorTest: regression for "今北産業" (no crash, 0 URLs) and
  for a bare "example.com:" host
- UrlParserTest: end-to-end regression for "今北産業" and "example.com:"

https://claude.ai/code/session_013rJ9iYndYVJgpYK2VazxL2
This commit is contained in:
Claude
2026-03-23 20:31:28 +00:00
parent 2b920fc47a
commit e31e3829a6
3 changed files with 109 additions and 0 deletions
@@ -281,6 +281,30 @@ class UrlParserTest {
Urls(withScheme = emptySet()),
)
/**
* Regression test for PR #1907: parsing a note whose content is only the Japanese phrase
* "今北産業" (a common internet abbreviation) must not throw a StringIndexOutOfBoundsException
* from Url.getPart() and must produce no detected URLs.
*/
@Test
fun testImakitaSangyo() =
test(
"今北産業",
Urls(),
)
/**
* Regression test for PR #1907: a URL that ends with ':' causes readEnd() to trim it,
* but the PORT marker index was already set to buffer.length (one past the trimmed URL).
* Accessing host/port must not throw StringIndexOutOfBoundsException.
*/
@Test
fun testUrlEndingWithColon() =
test(
"example.com:",
Urls(),
)
@Test
fun testHour() =
test(