Skip to content

Commit 1b50109

Browse files
Include property nodes in the long key check (jbeder#1140)
1 parent 4ae4cb7 commit 1b50109

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/emitter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ void Emitter::BlockMapPrepareNode(EmitterNodeType::value child) {
533533
if (m_pState->GetMapKeyFormat() == LongKey)
534534
m_pState->SetLongKey();
535535
if (child == EmitterNodeType::BlockSeq ||
536-
child == EmitterNodeType::BlockMap)
536+
child == EmitterNodeType::BlockMap ||
537+
child == EmitterNodeType::Property)
537538
m_pState->SetLongKey();
538539

539540
if (m_pState->CurGroupLongKey())

test/integration/emitter_test.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,38 @@ TEST_F(EmitterTest, BlockMapAsKey) {
431431
ExpectEmit("? key: value\n next key: next value\n: total value");
432432
}
433433

434+
TEST_F(EmitterTest, TaggedBlockMapAsKey) {
435+
out << BeginMap;
436+
out << Key;
437+
out << LocalTag("innerMap");
438+
out << BeginMap;
439+
out << Key << "key" << Value << "value";
440+
out << EndMap;
441+
out << Value;
442+
out << "outerValue";
443+
out << EndMap;
444+
445+
ExpectEmit(R"(? !innerMap
446+
key: value
447+
: outerValue)");
448+
}
449+
450+
TEST_F(EmitterTest, TaggedBlockListAsKey) {
451+
out << BeginMap;
452+
out << Key;
453+
out << LocalTag("innerList");
454+
out << BeginSeq;
455+
out << "listItem";
456+
out << EndSeq;
457+
out << Value;
458+
out << "outerValue";
459+
out << EndMap;
460+
461+
ExpectEmit(R"(? !innerList
462+
- listItem
463+
: outerValue)");
464+
}
465+
434466
TEST_F(EmitterTest, AliasAndAnchor) {
435467
out << BeginSeq;
436468
out << Anchor("fred");
@@ -520,7 +552,7 @@ TEST_F(EmitterTest, VerbatimTagInBlockMap) {
520552
out << Value << VerbatimTag("!waz") << "baz";
521553
out << EndMap;
522554

523-
ExpectEmit("!<!foo> bar: !<!waz> baz");
555+
ExpectEmit("? !<!foo> bar\n: !<!waz> baz");
524556
}
525557

526558
TEST_F(EmitterTest, VerbatimTagInFlowMap) {

0 commit comments

Comments
 (0)