diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2023-11-06 14:36:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 14:36:45 +0100 |
commit | 2be9751de81e86da9abe36104501db7b50ce3972 (patch) | |
tree | 17fd90f0326141ce83d0e404b417de7a74d3251c | |
parent | a6bc8ff27b15e0041dcde208abb1b4ff9d0fe278 (diff) | |
parent | 88a47d06459ce34bcea2a1761de519987550c54d (diff) |
Merge pull request #29245 from vespa-engine/arnej/escape-issue-messages
escape binary characters
-rw-r--r-- | searchlib/src/vespa/searchlib/engine/proto_converter.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/searchlib/src/vespa/searchlib/engine/proto_converter.cpp b/searchlib/src/vespa/searchlib/engine/proto_converter.cpp index 59e4b6e99f8..b21de31eab0 100644 --- a/searchlib/src/vespa/searchlib/engine/proto_converter.cpp +++ b/searchlib/src/vespa/searchlib/engine/proto_converter.cpp @@ -15,6 +15,26 @@ namespace search::engine { namespace { +std::string escape_message(const vespalib::string &item) { + static const char hexdigits[] = "0123456789ABCDEF"; + std::string r; + r.reserve(item.size()); + for (char c : item) { + if (c == '\\') { + r.push_back(c); + r.push_back(c); + } else if (c < 32 || c > 126) { + r.push_back('\\'); + r.push_back('x'); + r.push_back(hexdigits[0xF & (c >> 4)]); + r.push_back(hexdigits[0xF & c]); + } else { + r.push_back(c); + } + } + return r; +} + template <typename T> vespalib::string make_sort_spec(const T &sorting) { vespalib::string spec; @@ -166,7 +186,7 @@ ProtoConverter::search_reply_to_proto(const SearchReply &reply, ProtoSearchReply reply.my_issues->for_each_message([&](const vespalib::string &err_msg) { auto *err_obj = proto.add_errors(); - err_obj->set_message(err_msg); + err_obj->set_message(escape_message(err_msg)); }); } } @@ -223,7 +243,7 @@ ProtoConverter::docsum_reply_to_proto(const DocsumReply &reply, ProtoDocsumReply reply.issues().for_each_message([&](const vespalib::string &err_msg) { auto *err_obj = proto.add_errors(); - err_obj->set_message(err_msg); + err_obj->set_message(escape_message(err_msg)); }); } } |