Skip to content

Commit

Permalink
Handle a key with length over 1024 as a long key. (jbeder#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 authored and Dan Dees committed Oct 16, 2020
1 parent 470e520 commit 32e5a95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ Emitter& Emitter::Write(const std::string& str) {
Utils::ComputeStringFormat(str, m_pState->GetStringFormat(),
m_pState->CurGroupFlowType(), stringEscaping == StringEscaping::NonAscii);

if (strFormat == StringFormat::Literal)
if (strFormat == StringFormat::Literal || str.size() > 1024)
m_pState->SetMapKeyFormat(YAML::LongKey, FmtScope::Local);

PrepareNode(EmitterNodeType::Scalar);
Expand Down
9 changes: 8 additions & 1 deletion test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,23 @@ TEST_F(EmitterTest, SimpleLongKey) {
}

TEST_F(EmitterTest, SingleLongKey) {
const std::string shortKey(1024, 'a');
const std::string longKey(1025, 'a');
out << BeginMap;
out << Key << "age";
out << Value << "24";
out << LongKey << Key << "height";
out << Value << "5'9\"";
out << Key << "weight";
out << Value << 145;
out << Key << shortKey;
out << Value << "1";
out << Key << longKey;
out << Value << "1";
out << EndMap;

ExpectEmit("age: 24\n? height\n: 5'9\"\nweight: 145");
ExpectEmit("age: 24\n? height\n: 5'9\"\nweight: 145\n" + shortKey +
": 1\n? " + longKey + "\n: 1");
}

TEST_F(EmitterTest, ComplexLongKey) {
Expand Down

0 comments on commit 32e5a95

Please sign in to comment.