From ad1fccb5df31d0450bb5f564125820b65e1bebc1 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Fri, 30 Jan 2026 16:50:46 +0100 Subject: [PATCH] fix: return null if the provided string to parseYaml did not yield any result --- builtins.go | 3 +++ testdata/builtin_parseYaml_empty.golden | 1 + testdata/builtin_parseYaml_empty.jsonnet | 1 + testdata/builtin_parseYaml_empty.linter.golden | 0 4 files changed, 5 insertions(+) create mode 100644 testdata/builtin_parseYaml_empty.golden create mode 100644 testdata/builtin_parseYaml_empty.jsonnet create mode 100644 testdata/builtin_parseYaml_empty.linter.golden diff --git a/builtins.go b/builtins.go index 1703f06cd..57bd21753 100644 --- a/builtins.go +++ b/builtins.go @@ -1588,6 +1588,9 @@ func builtinParseYAML(i *interpreter, str value) (value, error) { elems = append(elems, elem) } + if len(elems) == 0 { + return &nullValue, nil + } if d.IsStream() { return jsonToValue(i, elems) } diff --git a/testdata/builtin_parseYaml_empty.golden b/testdata/builtin_parseYaml_empty.golden new file mode 100644 index 000000000..19765bd50 --- /dev/null +++ b/testdata/builtin_parseYaml_empty.golden @@ -0,0 +1 @@ +null diff --git a/testdata/builtin_parseYaml_empty.jsonnet b/testdata/builtin_parseYaml_empty.jsonnet new file mode 100644 index 000000000..2c3d290a6 --- /dev/null +++ b/testdata/builtin_parseYaml_empty.jsonnet @@ -0,0 +1 @@ +std.parseYaml("") diff --git a/testdata/builtin_parseYaml_empty.linter.golden b/testdata/builtin_parseYaml_empty.linter.golden new file mode 100644 index 000000000..e69de29bb