From 5b31a47a21dfe3caa4ab7e9c4cc10e8cd1116688 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 6 Feb 2022 10:05:08 +0100 Subject: [PATCH] Handle 2 edge cases in the new helpers. --- core/string.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/string.cpp b/core/string.cpp index 91352a3..b761d3c 100644 --- a/core/string.cpp +++ b/core/string.cpp @@ -1044,11 +1044,18 @@ void String::append_path(const String &path) { } void String::path_clean_end_slash() { - while (ends_with('/') || ends_with('\\')) { + // _size > 1, so if root is given ("/"), it will not be removed + + while (_size > 1 && (ends_with('/') || ends_with('\\'))) { pop_back(); } } void String::path_ensure_end_slash() { + //Don't add if empty string, as it would make it root on linux, which can easily become a serious bug + if (_size == 0) { + return; + } + if (!(ends_with('/') || ends_with('\\'))) { push_back(DEFAULT_DIRECTORY_SEPARATOR); }