Merge pull request #95184 from jsjtxietian/shader-include-relative

Fix `String::simplify_path` handling of relative paths to parent dir (`../`), fixes relative shader includes
This commit is contained in:
Rémi Verschelde 2024-08-17 00:46:11 +02:00
commit 49e5fbfbd2
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 5 additions and 9 deletions

View File

@ -4430,10 +4430,7 @@ String String::simplify_path() const {
dirs.remove_at(i); dirs.remove_at(i);
i--; i--;
} else if (d == "..") { } else if (d == "..") {
if (i == 0) { if (i != 0) {
dirs.remove_at(i);
i--;
} else {
dirs.remove_at(i); dirs.remove_at(i);
dirs.remove_at(i - 1); dirs.remove_at(i - 1);
i -= 2; i -= 2;

View File

@ -126,10 +126,9 @@ TEST_CASE("[ProjectSettings] localize_path") {
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\.\\filename"), "res://path/filename"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("path\\.\\filename"), "res://path/filename");
#endif #endif
// FIXME?: These checks pass, but that doesn't seems correct CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../filename"), "../filename");
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../filename"), "res://filename"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../path/filename"), "../path/filename");
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("../path/filename"), "res://path/filename"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("..\\path\\filename"), "../path/filename");
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("..\\path\\filename"), "res://path/filename");
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/filename"), "/testroot/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"); CHECK_EQ(ProjectSettings::get_singleton()->localize_path("/testroot/path/filename"), "/testroot/path/filename");

View File

@ -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 *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 *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 *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 }; static const bool abs[8] = { true, true, false, false, true, true, true, true };
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {