Fix linkify helper index out of bounds with parenthesis (#6140)

When parenthesis were mismatched by having more opening parenthesis than closing ones, we could end up incorrectly making the URLSpan `end` value greater than the actual text length, causing an `IndexOutOfBoundsException`
This commit is contained in:
Jorge Martin Espinosa 2026-02-05 09:33:38 +01:00 committed by GitHub
parent 2a2073fce0
commit 13d5068b6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -97,7 +97,7 @@ object LinkifyHelper {
val closingParenthesisCount = linkifiedTextLastPath.count { it == ')' }
val openingParenthesisCount = linkifiedTextLastPath.count { it == '(' }
// If it's not part of a pair, remove it from the link span by adjusting the end index
end -= closingParenthesisCount - openingParenthesisCount
end -= (closingParenthesisCount - openingParenthesisCount).coerceAtLeast(0)
}
return end
}