summaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
authorHugues Ross <hugues.ross@gmail.com>2020-07-28 13:16:57 -0400
committerGitHub <noreply@github.com>2020-07-28 19:16:57 +0200
commit3ce03d1c2a63d261c83f5962cd13212697f19472 (patch)
treef7c7db205866254865d18c711682c984c062b9cc /src/util/string.h
parentf948e2c58570df6bc77226b6066fec5ed90051ee (diff)
downloadminetest-3ce03d1c2a63d261c83f5962cd13212697f19472.tar.gz
minetest-3ce03d1c2a63d261c83f5962cd13212697f19472.tar.bz2
minetest-3ce03d1c2a63d261c83f5962cd13212697f19472.zip
Sanitize world directory names on create. Keep original name separate (#9432)
Blacklisted characters are replaced by '_' in the path. The display name is stored in world.mt, and duplicate file names are resolved by adding an incrementing suffix (_1, _2, _3, etc).
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/util/string.h b/src/util/string.h
index 185fb55e2..6fd11fadc 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -746,3 +746,11 @@ inline irr::core::stringw utf8_to_stringw(const std::string &input)
std::wstring str = utf8_to_wide(input);
return irr::core::stringw(str.c_str());
}
+
+/**
+ * Sanitize the name of a new directory. This consists of two stages:
+ * 1. Check for 'reserved filenames' that can't be used on some filesystems
+ * and prefix them
+ * 2. Remove 'unsafe' characters from the name by replacing them with '_'
+ */
+std::string sanitizeDirName(const std::string &str, const std::string &optional_prefix);