Skip to content

Commit

Permalink
fix: substring() can handle exceeding length
Browse files Browse the repository at this point in the history
If substring() is called with a given length that is greater than the string then it returns the remaining characters from the start index.

(cherry picked from commit 1f7478b)
  • Loading branch information
saig0 committed Aug 23, 2024
1 parent 741a2d1 commit 87c8bae
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ object StringBuiltinFunctions {
private def substringFunction3 = builtinFunction(
params = List("string", "start position", "length"),
invoke = { case List(ValString(string), ValNumber(start), ValNumber(length)) =>
val startIndex = stringIndex(string, start.intValue)
val endIndex = Math.min(startIndex + length.intValue, string.length)

ValString(
string.substring(
stringIndex(string, start.intValue),
stringIndex(string, start.intValue) + length.intValue
)
string.substring(startIndex, endIndex)
)
}
)
Expand Down

0 comments on commit 87c8bae

Please sign in to comment.