aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2020-03-26 20:28:38 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2020-03-28 17:32:28 +0000
commitc34164896c62fc6307b4cc72c060a277263590bb (patch)
tree0d4295591d6c716b9756cdd9c0ccb957a4f4ae59 /src
parent5236b2e267a58870239673c7ec85e5df0cb8fc8e (diff)
Bugfix: RPC: Remove final comma for last entry of fixed-size Arrays and Objects in RPCResult
JSON doesn't allow a trailing comma in Arrays/Objects
Diffstat (limited to 'src')
-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 1a79b3d37e..b404555193 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;