@@ -89,8 +89,8 @@ class RPCServerHandler
8989 auto req = boost::json::parse (request).as_object ();
9090 LOG (perfLog_.debug ()) << connection->tag () << " Adding to work queue" ;
9191
92- if (not connection->upgraded and not req. contains ( " params " ))
93- req[" params" ] = boost::json::array ({boost::json::object{}});
92+ if (not connection->upgraded and shouldReplaceParams (req ))
93+ req[JS ( params) ] = boost::json::array ({boost::json::object{}});
9494
9595 if (!rpcEngine_->post (
9696 [this , request = std::move (req), connection](boost::asio::yield_context yield) mutable {
@@ -267,6 +267,27 @@ class RPCServerHandler
267267 return web::detail::ErrorHelper (connection, request).sendInternalError ();
268268 }
269269 }
270+
271+ bool
272+ shouldReplaceParams (boost::json::object const & req) const
273+ {
274+ auto const hasParams = req.contains (JS (params));
275+ auto const paramsIsArray = hasParams and req.at (JS (params)).is_array ();
276+ auto const paramsIsEmptyString =
277+ hasParams and req.at (JS (params)).is_string () and req.at (JS (params)).as_string ().empty ();
278+ auto const paramsIsEmptyObject =
279+ hasParams and req.at (JS (params)).is_object () and req.at (JS (params)).as_object ().empty ();
280+ auto const paramsIsNull = hasParams and req.at (JS (params)).is_null ();
281+ auto const arrayIsEmpty = paramsIsArray and req.at (JS (params)).as_array ().empty ();
282+ auto const arrayIsNotEmpty = paramsIsArray and not req.at (JS (params)).as_array ().empty ();
283+ auto const firstArgIsNull = arrayIsNotEmpty and req.at (JS (params)).as_array ().at (0 ).is_null ();
284+ auto const firstArgIsEmptyString = arrayIsNotEmpty and req.at (JS (params)).as_array ().at (0 ).is_string () and
285+ req.at (JS (params)).as_array ().at (0 ).as_string ().empty ();
286+
287+ // Note: all this compatibility dance is to match `rippled` as close as possible
288+ return not hasParams or paramsIsEmptyString or paramsIsNull or paramsIsEmptyObject or arrayIsEmpty or
289+ firstArgIsEmptyString or firstArgIsNull;
290+ }
270291};
271292
272293} // namespace web
0 commit comments