summaryrefslogtreecommitdiffstats
path: root/core/os/os.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2023-01-14 15:07:28 +0100
committerJuan Linietsky <reduzio@gmail.com>2023-01-15 19:05:00 +0100
commit3a93efefee25360844d70d9b7994ae1644a6fd95 (patch)
tree6998495afb1f94966d3b26013864dd6e48bb0ef0 /core/os/os.cpp
parentac104a69b89409e7a8c0956f4e3e0b3bfa57c4c7 (diff)
downloadredot-engine-3a93efefee25360844d70d9b7994ae1644a6fd95.tar.gz
Fix cases of broken user:// paths.
* Properly validate paths when supplying the project name. * Ensures that the user data dir will always be valid. Fixes 69366.
Diffstat (limited to 'core/os/os.cpp')
-rw-r--r--core/os/os.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp
index c6fa8d307b..86469852e3 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -203,16 +203,26 @@ uint64_t OS::get_embedded_pck_offset() const {
}
// Helper function to ensure that a dir name/path will be valid on the OS
-String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
+String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_paths) const {
+ String safe_dir_name = p_dir_name;
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
- if (p_allow_dir_separator) {
+ if (p_allow_paths) {
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
invalid_chars.push_back("..");
+ safe_dir_name = safe_dir_name.replace("\\", "/").strip_edges();
} else {
invalid_chars.push_back("/");
+ invalid_chars.push_back("\\");
+ safe_dir_name = safe_dir_name.strip_edges();
+
+ // These directory names are invalid.
+ if (safe_dir_name == ".") {
+ safe_dir_name = "dot";
+ } else if (safe_dir_name == "..") {
+ safe_dir_name = "twodots";
+ }
}
- String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges();
for (int i = 0; i < invalid_chars.size(); i++) {
safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-");
}