From ac04c13f02e5d69483fb07577a2e6afa359683dc Mon Sep 17 00:00:00 2001 From: ppc64el <334245085+ppc64el@users.noreply.github.com> Date: Sat, 7 Nov 2026 05:27:34 +0300 Subject: [PATCH] load empty nodes tagged !!null as null HandleNode emitted a null event for a node with properties but no content only when the tag is the non-specific "?". An explicit tag:yaml.org,2002:null fell through to an empty scalar, so "test: !!null" loaded as an empty string. The core schema resolves empty content tagged null to null (yaml 1.2 spec 10.3.2), same as an untagged empty node, so emit OnNull for that tag too. Empty nodes with other explicit tags are unchanged. Regression test sits next to the null-tag tests from #897. --- src/singledocparser.cpp | 2 +- test/integration/load_node_test.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/singledocparser.cpp b/src/singledocparser.cpp index ca80bea2c..4200ad325 100644 --- a/src/singledocparser.cpp +++ b/src/singledocparser.cpp @@ -146,7 +146,7 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) { break; } - if (tag == "?") + if (tag == "?" || tag == "tag:yaml.org,2002:null") eventHandler.OnNull(mark, anchor); else eventHandler.OnScalar(mark, tag, anchor, ""); diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index e5f52bea6..e8b3d6b52 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -405,6 +405,13 @@ TEST(NodeTest, LoadQuotedNull) { EXPECT_EQ(node.as(), "null"); } +TEST(NodeTest, LoadNullWithNullTag) { + Node doc = Load("---\ntest: !!null \nfoo: bar"); + EXPECT_TRUE(doc["test"].IsNull()); + EXPECT_FALSE(doc["test"].IsScalar()); + EXPECT_EQ(doc["foo"].as(), "bar"); +} + TEST(NodeTest, LoadNonClosedQuotedString) { EXPECT_THROW(Load(R"("foo)"), ParserException); }