소스 검색

Merge pull request #100075 from demolke/simplify

Fix handling of leading `..` in simplify_path
Thaddeus Crews 9 달 전
부모
커밋
4b1a51d3e3
2개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      core/string/ustring.cpp
  2. 4 0
      tests/core/string/test_string.h

+ 1 - 1
core/string/ustring.cpp

@@ -4599,7 +4599,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;

+ 4 - 0
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") {