Skip to content

Commit 6b4f182

Browse files
author
MarcoFalke
committed
Merge #18444: RPC: Remove final comma for last entry of fixed-size arrays/objects in RPCResult
c341648 Bugfix: RPC: Remove final comma for last entry of fixed-size Arrays and Objects in RPCResult (Luke Dashjr) Pull request description: JSON doesn't allow a trailing comma in arrays Top commit has no ACKs. Tree-SHA512: 761502a05f447afc09c120f13bf23abd2aee83a7f5e5dadaf54c7e1c0c1280d83ee041ca6ca45998fb561e41b32d01067ec52a187c3bcc9d53303ea813bc212c
2 parents 1668c80 + c341648 commit 6b4f182

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/rpc/util.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_s
293293
struct Section {
294294
Section(const std::string& left, const std::string& right)
295295
: m_left{left}, m_right{right} {}
296-
const std::string m_left;
296+
std::string m_left;
297297
const std::string m_right;
298298
};
299299

@@ -645,6 +645,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
645645
}
646646
if (m_type == Type::ARR) {
647647
sections.PushSection({indent_next + "...", ""});
648+
} else {
649+
CHECK_NONFATAL(!m_inner.empty());
650+
// Remove final comma, which would be invalid JSON
651+
sections.m_sections.back().m_left.pop_back();
648652
}
649653
sections.PushSection({indent + "]" + maybe_separator, ""});
650654
return;
@@ -658,6 +662,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
658662
if (m_type == Type::OBJ_DYN) {
659663
// If the dictionary keys are dynamic, use three dots for continuation
660664
sections.PushSection({indent_next + "...", ""});
665+
} else {
666+
CHECK_NONFATAL(!m_inner.empty());
667+
// Remove final comma, which would be invalid JSON
668+
sections.m_sections.back().m_left.pop_back();
661669
}
662670
sections.PushSection({indent + "}" + maybe_separator, ""});
663671
return;

0 commit comments

Comments
 (0)