summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-01-26 15:23:59 +0100
committerGitHub <noreply@github.com>2021-01-26 15:23:59 +0100
commit1940197ac7eb820df34c0f920e31b4a8b26b891a (patch)
treef3694e67e68400b42a2d715f907be9d1a859d814
parent392d90fa65ce5d43790f6077a64f0c424f2cd0de (diff)
parent1d0437c95b7d91ad91b9cd14026b7c7996ef9358 (diff)
Merge pull request #45309 from VedatGunel/fix-string-ends-with
Fix String.ends_with() for empty string arguments
-rw-r--r--core/string/ustring.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 21336a99ec..6b6d0a8ab4 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -3074,11 +3074,16 @@ int String::rfindn(const String &p_str, int p_from) const {
}
bool String::ends_with(const String &p_string) const {
+ int l = p_string.length();
+ if (l == 0) {
+ return true;
+ }
+
int pos = rfind(p_string);
if (pos == -1) {
return false;
}
- return pos + p_string.length() == length();
+ return pos + l == length();
}
bool String::begins_with(const String &p_string) const {