From d29ac491f231d6831e98cc614902faed78718598 Mon Sep 17 00:00:00 2001 From: Dominik Bay Date: Mon, 29 Jun 2026 18:34:11 +0200 Subject: [PATCH 1/2] Restore single-argument Json.decode() in the DSL The recursion depth limit added to JsonDecode() in 2.16.2 gave the C++ function a second parameter with a default value. Function pointers do not carry default arguments, so the DSL function binding deduced an arity of 2 via boost::function_types::function_arity and required two arguments. As a result `Json.decode("...")` failed with "Too few arguments for function", an undocumented breaking change in a patch release. Wrap JsonDecode() in a single-argument shim (mirroring the existing JsonEncodeShim) so the registered function keeps its one-parameter contract while still applying the default depth limit internally. refs #10913 --- lib/base/json-script.cpp | 12 +++++++++++- test/base-json.cpp | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/base/json-script.cpp b/lib/base/json-script.cpp index 6fb3a18c892..903dd458ac7 100644 --- a/lib/base/json-script.cpp +++ b/lib/base/json-script.cpp @@ -15,12 +15,22 @@ static String JsonEncodeShim(const Value& value) return JsonEncode(value); } +static Value JsonDecodeShim(const String& data) +{ + /* Wrap JsonDecode() so that the DSL function keeps its single-argument + * signature. JsonDecode()'s depthLimit parameter has a default value, but + * function pointers don't carry defaults, so binding it directly would make + * depthLimit a required argument and break Json.decode("..."). See #10913. + */ + return JsonDecode(data); +} + INITIALIZE_ONCE([]() { Namespace::Ptr jsonNS = new Namespace(true); /* Methods */ jsonNS->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true)); - jsonNS->Set("decode", new Function("Json#decode", JsonDecode, { "value" }, true)); + jsonNS->Set("decode", new Function("Json#decode", JsonDecodeShim, { "value" }, true)); jsonNS->Freeze(); diff --git a/test/base-json.cpp b/test/base-json.cpp index 165c6110c12..cd629f33dfe 100644 --- a/test/base-json.cpp +++ b/test/base-json.cpp @@ -10,6 +10,7 @@ #include "base/io-engine.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" +#include "base/scriptglobal.hpp" #include "test/utils.hpp" #include #include @@ -147,6 +148,20 @@ BOOST_AUTO_TEST_CASE(decode) BOOST_CHECK(uint.IsNumber() && uint.Get() == 23.0); } +BOOST_AUTO_TEST_CASE(decode_dsl_single_argument) +{ + /* Regression test for #10913: the Json.decode() DSL function must accept a + * single argument. JsonDecode()'s optional depthLimit parameter must not + * leak into the function binding as a required argument. + */ + Namespace::Ptr systemNS = ScriptGlobal::Get("System"); + Namespace::Ptr jsonNS = systemNS->Get("Json"); + Function::Ptr decode = jsonNS->Get("decode"); + + BOOST_REQUIRE(decode); + BOOST_CHECK_EQUAL(decode->Invoke({ "2" }), Value(2)); +} + BOOST_AUTO_TEST_CASE(invalid1) { BOOST_CHECK_THROW(JsonDecode("\"1.7"), std::exception); From 326cbde4476f5d5a5695dca5ef8b2492c0280053 Mon Sep 17 00:00:00 2001 From: Dominik Bay Date: Mon, 29 Jun 2026 18:36:26 +0200 Subject: [PATCH 2/2] Add Dominik Bay to AUTHORS refs #10913 --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 5098c5bc265..dcf6a31326e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -83,6 +83,7 @@ Dirk Goetz Dirk Wening Dirk Melchers Dolf Schimmel +Dominik Bay Dominik Riva dominik-r-s <43005480+dominik-r-s@users.noreply.github.com> Edgar Fuß