diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index f8de2eb57..53f921785 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4205,8 +4205,17 @@ String String::path_clean_end_slash() const { String ret = *this; - while (ret.length() > 1 && (ret.ends_with("/") || ret.ends_with("\\"))) { - ret.resize(ret.length()); + int strip_to = ret.length() - 1; + + CharType c = ret[strip_to]; + + while (strip_to > 1 && (c == '/' || c == '\\')) { + --strip_to; + c = ret[strip_to]; + } + + if (ret.length() != strip_to + 1) { + ret.set_length(strip_to + 1); } return ret;