Skip to content

Android: link stitching assumes sorted, non-overlapping links #36

Open

Description

@developerjamiu
// android/.../TextClassifier.kt:94,136
val textBefore = text.substring(previousEnd, currentLink.start)
val textAfter = text.substring(links.last().end)

Both assume links arrive sorted by start offset and do not overlap. TextLinks.getLinks() returns a Collection with no documented ordering guarantee, so an out-of-order link throws StringIndexOutOfBoundsException.

iOS is safe here because NSDataDetector returns matches in order.

Fix: links.sortedBy { it.start } before the loop, and skip any link that starts before previousEnd.

Found during the v0.4.0 codebase audit.

Activity

  1. added
    bug
    platform: android
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplatform: android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions