From 39cf22a9c7268a5ec56786d687e38820ac262bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vedat=20G=C3=BCnel?= Date: Tue, 19 Jan 2021 15:14:25 +0300 Subject: [PATCH] Fix String.ends_with() for empty string arguments (cherry picked from commit 1d0437c95b7d91ad91b9cd14026b7c7996ef9358) --- core/ustring.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 389578caf6f..31147992b0b 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2709,10 +2709,15 @@ 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 = find_last(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 {