diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-08-17 00:46:11 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-08-17 00:46:11 +0200 |
commit | 49e5fbfbd2baba5528e2e2a9e6b404c2d9957624 (patch) | |
tree | c481971e7e7212c87e9efc45968926eeec6ebea4 | |
parent | 01b87a9a9c392062c239248d597a2b8d13a548eb (diff) | |
parent | 6cf9af2817a9751bf3d677165bf8ceb85f4186f0 (diff) | |
download | redot-engine-49e5fbfbd2baba5528e2e2a9e6b404c2d9957624.tar.gz |
Merge pull request #95184 from jsjtxietian/shader-include-relative
Fix `String::simplify_path` handling of relative paths to parent dir (`../`), fixes relative shader includes
-rw-r--r-- | core/string/ustring.cpp | 5 | ||||
-rw-r--r-- | tests/core/config/test_project_settings.h | 7 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 2 |
3 files changed, 5 insertions, 9 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 5a1f6925aa..3aaaf46b06 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4430,10 +4430,7 @@ String String::simplify_path() const { dirs.remove_at(i); i--; } else if (d == "..") { - if (i == 0) { - dirs.remove_at(i); - i--; - } else { + if (i != 0) { dirs.remove_at(i); dirs.remove_at(i - 1); i -= 2; diff --git a/tests/core/config/test_project_settings.h b/tests/core/config/test_project_settings.h index 8fc2489f8b..0e1058a626 100644 --- a/tests/core/config/test_project_settings.h +++ b/tests/core/config/test_project_settings.h @@ -126,10 +126,9 @@ TEST_CASE("[ProjectSettings] localize_path") { CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\.\\filename"), "res://path/filename"); #endif - // FIXME?: These checks pass, but that doesn't seems correct - CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../filename"), "res://filename"); - CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../path/filename"), "res://path/filename"); - CHECK_EQ(ProjectSettings::get_singleton()->localize_path("..\\path\\filename"), "res://path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../filename"), "../filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../path/filename"), "../path/filename"); + CHECK_EQ(ProjectSettings::get_singleton()->localize_path("..\\path\\filename"), "../path/filename"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/filename"), "/testroot/filename"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/path/filename"), "/testroot/path/filename"); diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 393ae16d0a..933eeff524 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -1620,7 +1620,7 @@ TEST_CASE("[String] Path functions") { static const char *base_name[8] = { "C:\\Godot\\project\\test", "/Godot/project/test", "../Godot/project/test", "Godot\\test", "C:\\test", "res://test", "user://test", "/" }; static const char *ext[8] = { "tscn", "xscn", "scn", "doc", "", "", "", "test" }; static const char *file[8] = { "test.tscn", "test.xscn", "test.scn", "test.doc", "test.", "test", "test", ".test" }; - static const char *simplified[8] = { "C:/Godot/project/test.tscn", "/Godot/project/test.xscn", "Godot/project/test.scn", "Godot/test.doc", "C:/test.", "res://test", "user://test", "/.test" }; + static const char *simplified[8] = { "C:/Godot/project/test.tscn", "/Godot/project/test.xscn", "../Godot/project/test.scn", "Godot/test.doc", "C:/test.", "res://test", "user://test", "/.test" }; static const bool abs[8] = { true, true, false, false, true, true, true, true }; for (int i = 0; i < 8; i++) { |