-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flow + Newline + EmptyMap bug #743
Comments
Can be fixed with diff: diff --git a/src/emitter.cpp b/src/emitter.cpp
index 016beb1..334d0d9 100644
--- a/src/emitter.cpp
+++ b/src/emitter.cpp
@@ -198,6 +198,7 @@ void Emitter::EmitEndSeq() {
if (!good())
return;
+ bool need_left_brace = !m_pState->HasBegunNode() || m_stream.comment();
if (m_pState->CurGroupChildCount() == 0)
m_pState->ForceFlow();
@@ -205,7 +206,7 @@ void Emitter::EmitEndSeq() {
if (m_stream.comment())
m_stream << "\n";
m_stream << IndentTo(m_pState->CurIndent());
- if (m_pState->CurGroupChildCount() == 0)
+ if (m_pState->CurGroupChildCount() == 0 && need_left_brace)
m_stream << "[";
m_stream << "]";
}
@@ -228,6 +229,7 @@ void Emitter::EmitEndMap() {
if (!good())
return;
+ bool need_left_brace = !m_pState->HasBegunNode() || m_stream.comment();
if (m_pState->CurGroupChildCount() == 0)
m_pState->ForceFlow();
@@ -235,7 +237,7 @@ void Emitter::EmitEndMap() {
if (m_stream.comment())
m_stream << "\n";
m_stream << IndentTo(m_pState->CurIndent());
- if (m_pState->CurGroupChildCount() == 0)
+ if (m_pState->CurGroupChildCount() == 0 && need_left_brace)
m_stream << "{";
m_stream << "}";
}
diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp
index 3a5783b..8ae2452 100644
--- a/test/integration/emitter_test.cpp
+++ b/test/integration/emitter_test.cpp
@@ -1075,5 +1075,15 @@ TEST_F(EmitterErrorTest, InvalidAlias) {
ExpectEmitError(ErrorMsg::INVALID_ALIAS);
}
+
+TEST_F(EmitterTest, FlowEmptyNewlineMap)
+{
+ out << YAML::BeginMap;
+ out << YAML::Key << "foo";
+ out << YAML::Value << YAML::Flow << YAML::BeginMap << YAML::Newline << YAML::EndMap;
+ out << YAML::EndMap;
+
+ ExpectEmit("foo: {\n }");
+}
} // namespace
} // namespace YAML
|
Fixed by #921. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add following test case:
but result is "foo: {\n {}\n"
The text was updated successfully, but these errors were encountered: