diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 9238e74ab1..30b30f5a84 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4608,7 +4608,7 @@ String String::simplify_path() const { dirs.remove_at(i); i--; } else if (d == "..") { - if (i != 0) { + if (i != 0 && dirs[i - 1] != "..") { dirs.remove_at(i); dirs.remove_at(i - 1); i -= 2; diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 9adc97e845..ea60230947 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -1687,6 +1687,10 @@ TEST_CASE("[String] Path functions") { for (int i = 0; i < 3; i++) { CHECK(String(file_name[i]).is_valid_filename() == valid[i]); } + + CHECK(String("res://texture.png") == String("res://folder/../folder/../texture.png").simplify_path()); + CHECK(String("res://texture.png") == String("res://folder/sub/../../texture.png").simplify_path()); + CHECK(String("res://../../texture.png") == String("res://../../texture.png").simplify_path()); } TEST_CASE("[String] hash") {