diff options
author | Hugues Ross <hugues.ross@gmail.com> | 2020-07-28 13:16:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-28 19:16:57 +0200 |
commit | 3ce03d1c2a63d261c83f5962cd13212697f19472 (patch) | |
tree | f7c7db205866254865d18c711682c984c062b9cc /src/script | |
parent | f948e2c58570df6bc77226b6066fec5ed90051ee (diff) | |
download | minetest-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/script')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index f32c477c2..e49ec4052 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -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"); |