diff --git a/src/exp.h b/src/exp.h index 84d14ae..3e12aba 100644 --- a/src/exp.h +++ b/src/exp.h @@ -137,7 +137,7 @@ namespace YAML // . In the block context - ? : must be not be followed with a space. // . In the flow context ? is illegal and : and - must not be followed with a space. inline const RegEx& PlainScalar() { - static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + Blank())); + static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx()))); return e; } inline const RegEx& PlainScalarInFlow() { diff --git a/test/emittertests.cpp b/test/emittertests.cpp index 9cba974..c369120 100644 --- a/test/emittertests.cpp +++ b/test/emittertests.cpp @@ -892,7 +892,16 @@ namespace Test out << YAML::EndSeq; desiredOutput = "- 1.23\n- 3.14159"; } - //////////////////////////////////////////////////////////////////////////////////////////////////////// + + void DashInBlockContext(YAML::Emitter& out, std::string& desiredOutput) + { + out << YAML::BeginMap; + out << YAML::Key << "key" << YAML::Value << "-"; + out << YAML::EndMap; + desiredOutput = "key: \"-\""; + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////// // incorrect emitting void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError) @@ -995,7 +1004,7 @@ namespace Test YAML::Node node; parser.GetNextDocument(node); #else - // Parse with the new API +// YAML::Node node = YAML::Load(output); #endif passed++; @@ -1113,6 +1122,7 @@ namespace Test RunEmitterTest(&Emitter::SingleChar, "single char", passed, total); RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total); RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total); + RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);