From 4d6b2f6f553f2509a5ef1bd27e1975b6e3c2213a Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 22 Dec 2023 15:35:35 +0100 Subject: [PATCH] Fix logic in String::substr_index. --- core/string/ustring.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 7e1785e8c..f8de2eb57 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -926,7 +926,7 @@ String String::substr(int p_from, int p_chars) const { String String::substr_index(const int start_index, const int end_index) const { int s = length(); - if (start_index < 0 || start_index >= s || end_index < 0 || start_index >= s) { + if (start_index < 0 || start_index >= s || end_index < 0) { return ""; } @@ -934,6 +934,10 @@ String String::substr_index(const int start_index, const int end_index) const { return ""; } + if (end_index >= s) { + return substr(start_index, (s - 1) - start_index); + } + return substr(start_index, end_index - start_index); }