diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-11-26 19:00:53 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-11-26 19:02:32 +0100 |
commit | af9c67db0c998bbd6f0de1ab0af98f9e615e6029 (patch) | |
tree | 018b3b3f6044e5c02cbaa1b44e01495e0013361c /core/os/os.cpp | |
parent | 9cf44c1c53f03b67143e606ab3d56680d73ac2c9 (diff) |
Allow customizing user:// path (folder in OS::get_data_path())
This allows to specify any valid folder name (including with subfolders) to use
as user:// on all platforms. The folder is constrained to the platform-specific
OS::get_data_path() (typically what `XDG_DATA_HOME` resolves to).
Fixes #13236.
Diffstat (limited to 'core/os/os.cpp')
-rw-r--r-- | core/os/os.cpp | 22 |
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 |