From d11c0059c489edf4eb9b382959c6068c9afe516e Mon Sep 17 00:00:00 2001 From: adfhkjafsdk Date: Thu, 2 Apr 2026 00:37:17 +0800 Subject: [PATCH 1/7] Fix bug on tags starting with "!!" --- src/emitfromevents.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/emitfromevents.cpp b/src/emitfromevents.cpp index 350bde648..09870780f 100644 --- a/src/emitfromevents.cpp +++ b/src/emitfromevents.cpp @@ -116,12 +116,16 @@ void EmitFromEvents::BeginNode() { } void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { - if (!tag.empty() && tag != "?" && tag != "!"){ - if (tag[0] == '!') { - m_emitter << LocalTag(std::string(tag.begin()+1, tag.end())); + if (!tag.empty() && tag != "?" && tag != "!") { + if (tag[0] == '!') { + if (tag != "!!" && tag[1] == '!') { + m_emitter << SecondaryTag(std::string(tag.begin() + 2, tag.end())); } else { - m_emitter << VerbatimTag(tag); + m_emitter << LocalTag(std::string(tag.begin() + 1, tag.end())); } + } else { + m_emitter << VerbatimTag(tag); + } } if (anchor) m_emitter << Anchor(ToString(anchor)); From 0f8ae3a209043b97244643a6fabf231cde5c867f Mon Sep 17 00:00:00 2001 From: adfhkjafsdk Date: Thu, 2 Apr 2026 13:37:39 +0800 Subject: [PATCH 2/7] Add test for emitting SecondaryTag --- test/integration/emitter_test.cpp | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp index f1472d6f3..810a5f526 100644 --- a/test/integration/emitter_test.cpp +++ b/test/integration/emitter_test.cpp @@ -660,6 +660,12 @@ TEST_F(EmitterTest, LocalTagRetainedAfterLoadingNode) { EXPECT_EQ(expected, emitter.c_str()); } +TEST_F(EmitterTest, SecondaryTag) { + out << SecondaryTag("str") << "123"; + + ExpectEmit("!!str 123"); +} + TEST_F(EmitterTest, ComplexDoc) { out << BeginMap; out << Key << "receipt"; @@ -975,16 +981,18 @@ TEST_F(EmitterTest, Unicode) { TEST_F(EmitterTest, DoubleQuotedUnicode) { out << DoubleQuoted << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2"; - ExpectEmit("\"\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2\""); + ExpectEmit("\"\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2\""); } TEST_F(EmitterTest, EscapedJsonString) { out.SetStringFormat(DoubleQuoted); out.SetOutputCharset(EscapeAsJson); out << "\" \\ " - "\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0A \x0B \x0C \x0D \x0E \x0F " - "\x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1F " - "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2"; + "\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0A \x0B \x0C \x0D " + "\x0E \x0F " + "\x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C " + "\x1D \x1E \x1F " + "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2"; ExpectEmit(R"("\" \\ \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t )" R"(\n \u000b \f \r \u000e \u000f \u0010 \u0011 \u0012 \u0013 )" @@ -994,22 +1002,14 @@ TEST_F(EmitterTest, EscapedJsonString) { } TEST_F(EmitterTest, EscapedCharacters) { - out << BeginSeq - << '\x00' - << '\x0C' - << '\x0D' - << EndSeq; + out << BeginSeq << '\x00' << '\x0C' << '\x0D' << EndSeq; ExpectEmit("- \"\\x00\"\n- \"\\f\"\n- \"\\r\""); } TEST_F(EmitterTest, CharactersEscapedAsJson) { out.SetOutputCharset(EscapeAsJson); - out << BeginSeq - << '\x00' - << '\x0C' - << '\x0D' - << EndSeq; + out << BeginSeq << '\x00' << '\x0C' << '\x0D' << EndSeq; ExpectEmit("- \"\\u0000\"\n- \"\\f\"\n- \"\\r\""); } @@ -1452,8 +1452,8 @@ TEST_F(EmitterTest, Infinity) { out << YAML::EndMap; ExpectEmit( - "foo: .inf\n" - "bar: .inf"); + "foo: .inf\n" + "bar: .inf"); } TEST_F(EmitterTest, NegInfinity) { @@ -1465,8 +1465,8 @@ TEST_F(EmitterTest, NegInfinity) { out << YAML::EndMap; ExpectEmit( - "foo: -.inf\n" - "bar: -.inf"); + "foo: -.inf\n" + "bar: -.inf"); } TEST_F(EmitterTest, NaN) { @@ -1478,11 +1478,11 @@ TEST_F(EmitterTest, NaN) { out << YAML::EndMap; ExpectEmit( - "foo: .nan\n" - "bar: .nan"); + "foo: .nan\n" + "bar: .nan"); } -TEST_F(EmitterTest, ComplexFlowSeqEmbeddingAMapWithNewLine) { +TEST_F(EmitterTest, ComplexFlowSeqEmbeddingAMapWithNewLine) { out << YAML::BeginMap; out << YAML::Key << "NodeA" << YAML::Value << YAML::BeginMap; From 18548c696b7b3016408bdbc2b737430f7916ecb8 Mon Sep 17 00:00:00 2001 From: adfhkjafsdk Date: Thu, 2 Apr 2026 14:44:18 +0800 Subject: [PATCH 3/7] Fix bug when calling SetTag with named tag handles. --- src/emitfromevents.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/emitfromevents.cpp b/src/emitfromevents.cpp index 09870780f..1840296cd 100644 --- a/src/emitfromevents.cpp +++ b/src/emitfromevents.cpp @@ -116,13 +116,21 @@ void EmitFromEvents::BeginNode() { } void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { - if (!tag.empty() && tag != "?" && tag != "!") { + if (!tag.empty() && tag != "?" && tag != "!" && tag != "!!") { if (tag[0] == '!') { - if (tag != "!!" && tag[1] == '!') { + auto prefix_end = tag.begin() + 1; + while (prefix_end != tag.end() && *prefix_end != '!') { + ++ prefix_end; + } + if(prefix_end == tag.begin() + 1) { m_emitter << SecondaryTag(std::string(tag.begin() + 2, tag.end())); - } else { + } else if (prefix_end == tag.end()) { m_emitter << LocalTag(std::string(tag.begin() + 1, tag.end())); - } + } else if (prefix_end + 1 != tag.end()){ + m_emitter << LocalTag(std::string(tag.begin() + 1, prefix_end), std::string(prefix_end + 1, tag.end())); + } else { + m_emitter << VerbatimTag(tag); + } } else { m_emitter << VerbatimTag(tag); } From 1c91829a2f407c09559cbf47b3cf6f5502ec60a3 Mon Sep 17 00:00:00 2001 From: adfhkjafsdk Date: Thu, 2 Apr 2026 14:46:35 +0800 Subject: [PATCH 4/7] Add test for SetTag --- test/integration/emitter_test.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp index 810a5f526..9c94de33c 100644 --- a/test/integration/emitter_test.cpp +++ b/test/integration/emitter_test.cpp @@ -666,6 +666,46 @@ TEST_F(EmitterTest, SecondaryTag) { ExpectEmit("!!str 123"); } +TEST_F(EmitterTest, SetVerbatimTag) { + Node node, root; + node = 42; + node.SetTag("hello"); + root["num"] = node; + out << root; + + ExpectEmit("num: ! 42"); +} + +TEST_F(EmitterTest, SetLocalTag) { + Node node, root; + node = 42; + node.SetTag("!foo"); + root["num"] = node; + out << root; + + ExpectEmit("num: !foo 42"); +} + +TEST_F(EmitterTest, SetLocalTagInNameHandle) { + Node node, root; + node = 42; + node.SetTag("!a!foo"); + root["num"] = node; + out << root; + + ExpectEmit("num: !a!foo 42"); +} + +TEST_F(EmitterTest, SetSecondaryTag) { + Node node, root; + node = 123; + node.SetTag("!!str"); + root["hello"] = node; + out << root; + + ExpectEmit("hello: !!str 123"); +} + TEST_F(EmitterTest, ComplexDoc) { out << BeginMap; out << Key << "receipt"; From ab1eb9043ce7b7b99554d3775681a11288513335 Mon Sep 17 00:00:00 2001 From: rzh789ABC <124703704+adfhkjafsdk@users.noreply.github.com> Date: Thu, 2 Apr 2026 17:17:34 +0800 Subject: [PATCH 5/7] Update src/emitfromevents.cpp fix style glitch Co-authored-by: Simon Gene Gottlieb --- src/emitfromevents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emitfromevents.cpp b/src/emitfromevents.cpp index 1840296cd..d42dd5f96 100644 --- a/src/emitfromevents.cpp +++ b/src/emitfromevents.cpp @@ -120,7 +120,7 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { if (tag[0] == '!') { auto prefix_end = tag.begin() + 1; while (prefix_end != tag.end() && *prefix_end != '!') { - ++ prefix_end; + ++prefix_end; } if(prefix_end == tag.begin() + 1) { m_emitter << SecondaryTag(std::string(tag.begin() + 2, tag.end())); From 5e22925df09cf9825f2fdc8b2ef31f2084e88406 Mon Sep 17 00:00:00 2001 From: rzh789ABC <124703704+adfhkjafsdk@users.noreply.github.com> Date: Thu, 2 Apr 2026 17:17:49 +0800 Subject: [PATCH 6/7] Update src/emitfromevents.cpp fix style glitch Co-authored-by: Simon Gene Gottlieb --- src/emitfromevents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emitfromevents.cpp b/src/emitfromevents.cpp index d42dd5f96..a719fc608 100644 --- a/src/emitfromevents.cpp +++ b/src/emitfromevents.cpp @@ -122,7 +122,7 @@ void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { while (prefix_end != tag.end() && *prefix_end != '!') { ++prefix_end; } - if(prefix_end == tag.begin() + 1) { + if (prefix_end == tag.begin() + 1) { m_emitter << SecondaryTag(std::string(tag.begin() + 2, tag.end())); } else if (prefix_end == tag.end()) { m_emitter << LocalTag(std::string(tag.begin() + 1, tag.end())); From 70edb7797909ccdd64a9eccfc7455490e20c7468 Mon Sep 17 00:00:00 2001 From: adfhkjafsdk Date: Thu, 2 Apr 2026 17:22:21 +0800 Subject: [PATCH 7/7] fix style glitch: use space for indentation --- src/emitfromevents.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/emitfromevents.cpp b/src/emitfromevents.cpp index a719fc608..fdd4d701f 100644 --- a/src/emitfromevents.cpp +++ b/src/emitfromevents.cpp @@ -118,19 +118,19 @@ void EmitFromEvents::BeginNode() { void EmitFromEvents::EmitProps(const std::string& tag, anchor_t anchor) { if (!tag.empty() && tag != "?" && tag != "!" && tag != "!!") { if (tag[0] == '!') { - auto prefix_end = tag.begin() + 1; - while (prefix_end != tag.end() && *prefix_end != '!') { - ++prefix_end; - } - if (prefix_end == tag.begin() + 1) { + auto prefix_end = tag.begin() + 1; + while (prefix_end != tag.end() && *prefix_end != '!') { + ++prefix_end; + } + if (prefix_end == tag.begin() + 1) { m_emitter << SecondaryTag(std::string(tag.begin() + 2, tag.end())); } else if (prefix_end == tag.end()) { m_emitter << LocalTag(std::string(tag.begin() + 1, tag.end())); } else if (prefix_end + 1 != tag.end()){ - m_emitter << LocalTag(std::string(tag.begin() + 1, prefix_end), std::string(prefix_end + 1, tag.end())); - } else { - m_emitter << VerbatimTag(tag); - } + m_emitter << LocalTag(std::string(tag.begin() + 1, prefix_end), std::string(prefix_end + 1, tag.end())); + } else { + m_emitter << VerbatimTag(tag); + } } else { m_emitter << VerbatimTag(tag); }