summaryrefslogtreecommitdiff
path: root/core/os/os.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/os/os.cpp')
-rw-r--r--core/os/os.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp
index a39dfcc003..8088a6fa74 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -279,14 +279,22 @@ String OS::get_locale() const {
return "en";
}
-// Helper function used by OS_Unix and OS_Windows
-String OS::get_safe_application_name() const {
- String an = ProjectSettings::get_singleton()->get("application/config/name");
- Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" ");
- for (int i = 0; i < invalid_char.size(); i++) {
- an = an.replace(invalid_char[i], "-");
+// 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 {
+
+ Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
+ if (p_allow_dir_separator) {
+ // Dir separators are allowed, but disallow ".." to avoid going up the filesystem
+ invalid_chars.push_back("..");
+ } else {
+ invalid_chars.push_back("/");
+ }
+
+ 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], "-");
}
- return an;
+ return safe_dir_name;
}
// Path to data, config, cache, etc. OS-specific folders