diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/logv2/json_formatter.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/logv2/json_formatter.cpp')
| -rw-r--r-- | src/mongo/logv2/json_formatter.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/mongo/logv2/json_formatter.cpp b/src/mongo/logv2/json_formatter.cpp index 58111121423..cbcfc85f121 100644 --- a/src/mongo/logv2/json_formatter.cpp +++ b/src/mongo/logv2/json_formatter.cpp @@ -168,27 +168,16 @@ private: void storeQuoted(StringData name, const T& value) { format_to(std::back_inserter(_buffer), FMT_COMPILE(R"({}"{}":")"), _separator, name); std::size_t before = _buffer.size(); - std::size_t wouldWrite = 0; - std::size_t written = 0; - str::escapeForJSON( - _buffer, value, _attributeMaxSize ? _attributeMaxSize : std::string::npos, &wouldWrite); - written = _buffer.size() - before; - - if (wouldWrite > written) { - // The bounded escape may have reached the limit and - // stopped writing while in the middle of a UTF-8 sequence, - // in which case the incomplete UTF-8 octets at the tail of the - // buffer have to be trimmed. - // Push a dummy byte so that the UTF-8 safe truncation - // will truncate back down to the correct size. - _buffer.push_back('x'); + str::escapeForJSON(_buffer, value); + if (_attributeMaxSize != 0) { auto truncatedEnd = - str::UTF8SafeTruncation(_buffer.begin() + before, _buffer.end(), written); - - BSONObjBuilder truncationInfo = _truncated.subobjStart(name); - truncationInfo.append("type"_sd, typeName(BSONType::String)); - truncationInfo.append("size"_sd, static_cast<int64_t>(wouldWrite)); - truncationInfo.done(); + str::UTF8SafeTruncation(_buffer.begin() + before, _buffer.end(), _attributeMaxSize); + if (truncatedEnd != _buffer.end()) { + BSONObjBuilder truncationInfo = _truncated.subobjStart(name); + truncationInfo.append("type"_sd, typeName(BSONType::String)); + truncationInfo.append("size"_sd, static_cast<int64_t>(_buffer.size() - before)); + truncationInfo.done(); + } _buffer.resize(truncatedEnd - _buffer.begin()); } |
