mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 08:35:20 +02:00
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).
This commit is contained in:
@@ -618,7 +618,7 @@ int ModApiMainMenu::l_create_world(lua_State *L)
|
||||
|
||||
std::string path = porting::path_user + DIR_DELIM
|
||||
"worlds" + DIR_DELIM
|
||||
+ name;
|
||||
+ sanitizeDirName(name, "world_");
|
||||
|
||||
std::vector<SubgameSpec> games = getAvailableGames();
|
||||
|
||||
@@ -626,10 +626,11 @@ int ModApiMainMenu::l_create_world(lua_State *L)
|
||||
(gameidx < (int) games.size())) {
|
||||
|
||||
// Create world if it doesn't exist
|
||||
if (!loadGameConfAndInitWorld(path, games[gameidx])) {
|
||||
lua_pushstring(L, "Failed to initialize world");
|
||||
} else {
|
||||
try {
|
||||
loadGameConfAndInitWorld(path, name, games[gameidx], true);
|
||||
lua_pushnil(L);
|
||||
} catch (const BaseException &e) {
|
||||
lua_pushstring(L, (std::string("Failed to initialize world: ") + e.what()).c_str());
|
||||
}
|
||||
} else {
|
||||
lua_pushstring(L, "Invalid game index");
|
||||
|
Reference in New Issue
Block a user