Merge pull request #10921 from Icinga/backport-10914-to-support/2.16
Some checks are pending
Linux / alpine:bash (push) Waiting to run
Linux / amazonlinux:2 (push) Waiting to run
Linux / amazonlinux:2023 (push) Waiting to run
Linux / debian:11 (linux/386) (push) Waiting to run
Linux / debian:11 (push) Waiting to run
Linux / debian:12 (linux/386) (push) Waiting to run
Linux / debian:12 (push) Waiting to run
Linux / debian:13 (push) Waiting to run
Linux / fedora:41 (push) Waiting to run
Linux / fedora:42 (push) Waiting to run
Linux / fedora:43 (push) Waiting to run
Linux / fedora:44 (push) Waiting to run
Linux / opensuse/leap:15.6 (push) Waiting to run
Linux / opensuse/leap:16.0 (push) Waiting to run
Linux / registry.suse.com/bci/bci-base:16.0 (push) Waiting to run
Linux / registry.suse.com/suse/sle15:15.6 (push) Waiting to run
Linux / registry.suse.com/suse/sle15:15.7 (push) Waiting to run
Linux / rockylinux/rockylinux:10 (push) Waiting to run
Linux / rockylinux:8 (push) Waiting to run
Linux / rockylinux:9 (push) Waiting to run
Linux / ubuntu:22.04 (push) Waiting to run
Linux / ubuntu:24.04 (push) Waiting to run
Linux / ubuntu:25.04 (push) Waiting to run
Linux / ubuntu:25.10 (push) Waiting to run
Linux / ubuntu:26.04 (push) Waiting to run
Windows / Windows (push) Waiting to run

[Backport support/2.16] Restore single-argument Json.decode() in the DSL
This commit is contained in:
Alexander Aleksandrovič Klimov 2026-06-30 18:03:51 +02:00 committed by GitHub
commit be84a7f2cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View file

@ -82,6 +82,7 @@ Dirk Goetz <dirk.goetz@icinga.com>
Dirk Wening <dirk.wening@netways.de>
Dirk Melchers <dirk@dirk-melchers.de>
Dolf Schimmel <dolf@transip.nl>
Dominik Bay <dominik@bay.sh>
Dominik Riva <driva@protonmail.com>
dominik-r-s <43005480+dominik-r-s@users.noreply.github.com>
Edgar Fuß <ef@math.uni-bonn.de>

View file

@ -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();

View file

@ -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 <boost/algorithm/string/replace.hpp>
#include <BoostTestTargetConfig.h>
@ -147,6 +148,20 @@ BOOST_AUTO_TEST_CASE(decode)
BOOST_CHECK(uint.IsNumber() && uint.Get<double>() == 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);