forked from Mirrorlandia_minetest/minetest
LuaSettings: Sanitize setting name strings
This commit is contained in:
parent
16781da4f9
commit
360660947b
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user