Skip to content

Commit

Permalink
Fix handling of leading .. in simplify_path
Browse files Browse the repository at this point in the history
Prior to this `..\..\texture.png` was incorrectly simplified to `texture.png`

(cherry picked from commit 964e2b3)
  • Loading branch information
demolke authored and Spartan322 committed Jan 18, 2025
1 parent 31b13f3 commit 736126b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4510,7 +4510,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;
Expand Down
4 changes: 4 additions & 0 deletions tests/core/string/test_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,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") {
Expand Down

0 comments on commit 736126b

Please sign in to comment.