mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
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
This commit is contained in:
parent
5236b2e267
commit
c34164896c
1 changed files with 9 additions and 1 deletions
|
@ -293,7 +293,7 @@ UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_s
|
||||||
struct Section {
|
struct Section {
|
||||||
Section(const std::string& left, const std::string& right)
|
Section(const std::string& left, const std::string& right)
|
||||||
: m_left{left}, m_right{right} {}
|
: m_left{left}, m_right{right} {}
|
||||||
const std::string m_left;
|
std::string m_left;
|
||||||
const std::string m_right;
|
const std::string m_right;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -645,6 +645,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
|
||||||
}
|
}
|
||||||
if (m_type == Type::ARR) {
|
if (m_type == Type::ARR) {
|
||||||
sections.PushSection({indent_next + "...", ""});
|
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, ""});
|
sections.PushSection({indent + "]" + maybe_separator, ""});
|
||||||
return;
|
return;
|
||||||
|
@ -658,6 +662,10 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const
|
||||||
if (m_type == Type::OBJ_DYN) {
|
if (m_type == Type::OBJ_DYN) {
|
||||||
// If the dictionary keys are dynamic, use three dots for continuation
|
// If the dictionary keys are dynamic, use three dots for continuation
|
||||||
sections.PushSection({indent_next + "...", ""});
|
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, ""});
|
sections.PushSection({indent + "}" + maybe_separator, ""});
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue