From 7e129c9b6495a987019738fe32997f8184a1e15e Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Tue, 6 Sep 2011 00:24:10 -0500 Subject: [PATCH] Fixed empty string emitter bug (it now with auto-quote it --- src/emitterutils.cpp | 3 +++ test/emittertests.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index 5bc0ba9..be512af 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -128,6 +128,9 @@ namespace YAML } bool IsValidPlainScalar(const std::string& str, bool inFlow, bool allowOnlyAscii) { + if(str.empty()) + return false; + // first check the start const RegEx& start = (inFlow ? Exp::PlainScalarInFlow() : Exp::PlainScalar()); if(!start.Matches(str)) diff --git a/test/emittertests.cpp b/test/emittertests.cpp index 329ed3b..a7c13d8 100644 --- a/test/emittertests.cpp +++ b/test/emittertests.cpp @@ -846,6 +846,14 @@ namespace Test out << "Oops"; desiredOutput = "Hi\n---\nBye\n---\nOops"; } + + void EmptyString(YAML::Emitter& out, std::string& desiredOutput) + { + out << YAML::BeginMap; + out << YAML::Key << "key" << YAML::Value << ""; + out << YAML::EndMap; + desiredOutput = "key: \"\""; + } //////////////////////////////////////////////////////////////////////////////////////////////////////// // incorrect emitting @@ -1058,6 +1066,7 @@ namespace Test RunEmitterTest(&Emitter::BoolFormatting, "bool formatting", passed, total); RunEmitterTest(&Emitter::DocStartAndEnd, "doc start and end", passed, total); RunEmitterTest(&Emitter::ImplicitDocStart, "implicit doc start", passed, total); + RunEmitterTest(&Emitter::EmptyString, "empty string", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);