aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-01-28 23:53:58 +0100
committerest31 <MTest31@outlook.com>2016-01-28 23:53:58 +0100
commit860d70bd0e228ee542e3e559961bfc7e56888d77 (patch)
tree61e29746f8e88acfdb6beb3a90ed6782e97d6ca4 /src/script/lua_api
parente52ebda8b2273bbd80573838d6dbafb31ee2cd2b (diff)
downloadminetest-860d70bd0e228ee542e3e559961bfc7e56888d77.tar.gz
minetest-860d70bd0e228ee542e3e559961bfc7e56888d77.tar.bz2
minetest-860d70bd0e228ee542e3e559961bfc7e56888d77.zip
Don't print whole json data buffer to errorstream on error
`errorstream` must not be overly verbose as clientside it is directly printed onto the ingame chat window. These days, the serverlist can contain > 200k bytes, so better print it to warningstream if the data buffer is too long.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_util.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 3f7e15acf..39863b987 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -161,8 +161,14 @@ int ModApiUtil::l_parse_json(lua_State *L)
if (!reader.parse(stream, root)) {
errorstream << "Failed to parse json data "
<< reader.getFormattedErrorMessages();
- errorstream << "data: \"" << jsonstr << "\""
- << std::endl;
+ size_t jlen = strlen(jsonstr);
+ if (jlen > 100) {
+ errorstream << "Data (" << jlen
+ << " bytes) printed to warningstream." << std::endl;
+ warningstream << "data: \"" << jsonstr << "\"" << std::endl;
+ } else {
+ errorstream << "data: \"" << jsonstr << "\"" << std::endl;
+ }
lua_pushnil(L);
return 1;
}