Forráskód Böngészése

Merge pull request #45309 from VedatGunel/fix-string-ends-with

Fix String.ends_with() for empty string arguments
Rémi Verschelde 4 éve
szülő
commit
1940197ac7
1 módosított fájl, 6 hozzáadás és 1 törlés
  1. 6 1
      core/string/ustring.cpp

+ 6 - 1
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 {