Skip to content

Commit 860d70b

Browse files
committedJan 28, 2016
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.
1 parent e52ebda commit 860d70b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
 

‎src/convert_json.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ Json::Value fetchJsonValue(const std::string &url,
5252
if (!reader.parse(stream, root)) {
5353
errorstream << "URL: " << url << std::endl;
5454
errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
55-
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
55+
if (fetch_result.data.size() > 100) {
56+
errorstream << "Data (" << fetch_result.data.size()
57+
<< " bytes) printed to warningstream." << std::endl;
58+
warningstream << "data: \"" << fetch_result.data << "\"" << std::endl;
59+
} else {
60+
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
61+
}
5662
return Json::Value();
5763
}
5864

‎src/script/lua_api/l_util.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ int ModApiUtil::l_parse_json(lua_State *L)
161161
if (!reader.parse(stream, root)) {
162162
errorstream << "Failed to parse json data "
163163
<< reader.getFormattedErrorMessages();
164-
errorstream << "data: \"" << jsonstr << "\""
165-
<< std::endl;
164+
size_t jlen = strlen(jsonstr);
165+
if (jlen > 100) {
166+
errorstream << "Data (" << jlen
167+
<< " bytes) printed to warningstream." << std::endl;
168+
warningstream << "data: \"" << jsonstr << "\"" << std::endl;
169+
} else {
170+
errorstream << "data: \"" << jsonstr << "\"" << std::endl;
171+
}
166172
lua_pushnil(L);
167173
return 1;
168174
}

0 commit comments

Comments
 (0)