浏览代码

Merge pull request #29315 from akien-mga/fix-paths-localization

Don't localize paths that contain but are not in the resource path
Rémi Verschelde 6 年之前
父节点
当前提交
fcb60fa2cd
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      core/project_settings.cpp

+ 10 - 2
core/project_settings.cpp

@@ -75,11 +75,19 @@ String ProjectSettings::localize_path(const String &p_path) const {
 
 		memdelete(dir);
 
-		if (!cwd.begins_with(resource_path)) {
+		// Ensure that we end with a '/'.
+		// This is important to ensure that we do not wrongly localize the resource path
+		// in an absolute path that just happens to contain this string but points to a
+		// different folder (e.g. "/my/project" as resource_path would be contained in
+		// "/my/project_data", even though the latter is not part of res://.
+		// `plus_file("")` is an easy way to ensure we have a trailing '/'.
+		const String res_path = resource_path.plus_file("");
+
+		if (!cwd.begins_with(res_path)) {
 			return p_path;
 		};
 
-		return cwd.replace_first(resource_path, "res:/");
+		return cwd.replace_first(res_path, "res://");
 	} else {
 
 		memdelete(dir);