aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-03-28 15:13:01 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-03-28 15:13:13 -0400
commit6b4f182806d62f00035cd9edc8ea8b837138e7f0 (patch)
tree813f1326992f66a1302f12a07d52354631bc0e7d
parent1668c80bdcc3c2742fbe220573f5b5248129f3fa (diff)
parentc34164896c62fc6307b4cc72c060a277263590bb (diff)
Merge #18444: RPC: Remove final comma for last entry of fixed-size arrays/objects in RPCResult
c34164896c62fc6307b4cc72c060a277263590bb 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
-rw-r--r--src/rpc/util.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index 4ba84d2515..32e0e1ec27 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -293,7 +293,7 @@ UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_s
struct Section {
Section(const std::string& left, const std::string& right)
: m_left{left}, m_right{right} {}
- const std::string m_left;
+ std::string m_left;
const std::string m_right;
};
@@ -645,6 +645,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
}
if (m_type == Type::ARR) {
sections.PushSection({indent_next + "...", ""});
+ } else {
+ CHECK_NONFATAL(!m_inner.empty());
+ // Remove final comma, which would be invalid JSON
+ sections.m_sections.back().m_left.pop_back();
}
sections.PushSection({indent + "]" + maybe_separator, ""});
return;
@@ -658,6 +662,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
if (m_type == Type::OBJ_DYN) {
// If the dictionary keys are dynamic, use three dots for continuation
sections.PushSection({indent_next + "...", ""});
+ } else {
+ CHECK_NONFATAL(!m_inner.empty());
+ // Remove final comma, which would be invalid JSON
+ sections.m_sections.back().m_left.pop_back();
}
sections.PushSection({indent + "}" + maybe_separator, ""});
return;