From 07bf003b7990047a55e8d3031ffeb4f937295830 Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Fri, 18 Jan 2019 22:15:20 +0200 Subject: [PATCH] Allow WML tags with leading underscore (#3877) @gfgtdf pointed out that the WML parser can deal with such tags after all. I had missed that when I implemented the check that the game state is valid WML before saving it (commit 3bc36efa5898a95ce793195e24b4dee1b546c222). Such tags are still disallowed in the Lua API because allowing them would be an API change. --- src/config.cpp | 4 ++-- src/scripting/lua_common.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index ed2d22210222..b0e7f96cc3a0 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -186,8 +186,8 @@ bool config::valid_tag(config_key_type name) if(name == "") { // Empty strings not allowed return false; - } else if(name[0] == '_') { - // Underscore can't be the first character + } else if(name == "_") { + // A lone underscore isn't a valid tag name return false; } else { return std::all_of(name.begin(), name.end(), [](const char& c) diff --git a/src/scripting/lua_common.cpp b/src/scripting/lua_common.cpp index 22abc95a3002..aea38a01f3c5 100644 --- a/src/scripting/lua_common.cpp +++ b/src/scripting/lua_common.cpp @@ -745,7 +745,7 @@ bool luaW_toconfig(lua_State *L, int index, config &cfg) if (!lua_istable(L, -1)) return_misformed(); lua_rawgeti(L, -1, 1); char const *m = lua_tostring(L, -1); - if (!m || !config::valid_tag(m)) return_misformed(); + if (!m || !config::valid_tag(m) || m[0] == '_') return_misformed(); lua_rawgeti(L, -2, 2); if (!luaW_toconfig(L, -1, cfg.add_child(m))) return_misformed();