fix: prevent StringIndexOutOfBoundsException in Url.getPart()
When UrlDetector.readEnd() trims the last character from URLs ending with characters like '.', ',', etc., the urlMarker indices remain based on the original buffer length. This caused getPart() to call substring() with an end index beyond the trimmed URL's length. Fix by clamping the end index to originalUrl.length and guarding against an out-of-bounds start index. https://claude.ai/code/session_014Q2SvTE5vKgUm1w8dPVjYo
This commit is contained in:
@@ -228,11 +228,17 @@ class Url(
|
||||
return null
|
||||
}
|
||||
|
||||
val startIndex = urlMarker.indexOf(part)
|
||||
if (startIndex < 0 || startIndex >= originalUrl.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
val nextPart = nextExistingPart(part)
|
||||
return if (nextPart == null) {
|
||||
originalUrl.substring(urlMarker.indexOf(part))
|
||||
originalUrl.substring(startIndex)
|
||||
} else {
|
||||
originalUrl.substring(urlMarker.indexOf(part), urlMarker.indexOf(nextPart))
|
||||
val endIndex = urlMarker.indexOf(nextPart)
|
||||
originalUrl.substring(startIndex, minOf(endIndex, originalUrl.length))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user