LuaSettings: Sanitize setting name strings
authorkwolekr <kwolekr@minetest.net>
Mon, 1 Dec 2014 00:01:37 +0000 (19:01 -0500)
committerkwolekr <kwolekr@minetest.net>
Mon, 1 Dec 2014 00:01:54 +0000 (19:01 -0500)
src/script/lua_api/l_settings.cpp
src/settings.cpp
src/settings.h

index 13a88ee9598b4ffcdd37910e4fec3f2476f4a6c6..c2c6f009d8c38a4f55c369b8d89e8b2a74c4359d 100644 (file)
@@ -73,7 +73,7 @@ int LuaSettings::l_set(lua_State* L)
        std::string key = std::string(luaL_checkstring(L, 2));
        const char* value = luaL_checkstring(L, 3);
 
-       o->m_settings->set(key, value);
+       o->m_settings->set(Settings::sanitizeString(key), value);
 
        return 1;
 }
index 9485c7d74fa6414090978faa131dfb654e3cdf4a..34348cc06fde032ff6e0e8ef2d710321b1e15896 100644 (file)
@@ -63,6 +63,16 @@ Settings & Settings::operator = (const Settings &other)
 }
 
 
+std::string Settings::sanitizeString(const std::string &value)
+{
+       std::string str = value;
+       for (const char *s = "\t\n\v\f\r\b =\""; *s; s++)
+               str.erase(std::remove(str.begin(), str.end(), *s), str.end());
+
+       return str;
+}
+
+
 std::string Settings::getMultiline(std::istream &is)
 {
        std::string value;
index d0bd203d30525292df257b7046abc6541fc21cca..542fae2a40bbddc51acd7d5111c73daeefa44400 100644 (file)
@@ -117,6 +117,7 @@ public:
                const std::string &end, u32 tab_depth=0);
 
        static std::string getMultiline(std::istream &is);
+       static std::string sanitizeString(const std::string &value);
        static void printValue(std::ostream &os, const std::string &name,
                const SettingsEntry &entry, bool is_value_multiline, u32 tab_depth=0);