From 490265cf22f5c4bff9d4f707de2397687a941ee8 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 8 Nov 2012 18:52:54 -0600 Subject: [PATCH 1/4] Added failing tests for emitter ? at the start of a value --- test/emittertests.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/emittertests.cpp b/test/emittertests.cpp index 690de05..de3d14c 100644 --- a/test/emittertests.cpp +++ b/test/emittertests.cpp @@ -946,6 +946,15 @@ namespace Test desiredOutput = "\"Hello\\nWorld\""; } + void QuoteQuestionMark(YAML::Emitter& out, std::string& desiredOutput) + { + out << YAML::BeginMap; + out << "a" << "?foo"; + out << YAML::EndMap; + + desiredOutput = "a: \"?foo\""; + } + //////////////////////////////////////////////////////////////////////////////// // incorrect emitting @@ -1167,6 +1176,7 @@ namespace Test RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total); RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total); RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total); + RunEmitterTest(&Emitter::QuoteQuestionMark, "quote question mark", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total); From 4e1bdd08d3f61d49b0880ff39edaf4965a6f8b61 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 8 Nov 2012 18:54:53 -0600 Subject: [PATCH 2/4] Removed that failing test - I don't think the parser is correct here --- test/emittertests.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/emittertests.cpp b/test/emittertests.cpp index de3d14c..690de05 100644 --- a/test/emittertests.cpp +++ b/test/emittertests.cpp @@ -946,15 +946,6 @@ namespace Test desiredOutput = "\"Hello\\nWorld\""; } - void QuoteQuestionMark(YAML::Emitter& out, std::string& desiredOutput) - { - out << YAML::BeginMap; - out << "a" << "?foo"; - out << YAML::EndMap; - - desiredOutput = "a: \"?foo\""; - } - //////////////////////////////////////////////////////////////////////////////// // incorrect emitting @@ -1176,7 +1167,6 @@ namespace Test RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total); RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total); RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total); - RunEmitterTest(&Emitter::QuoteQuestionMark, "quote question mark", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total); RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total); From 15b60e2a3bef267fd88d94a57fd6a552a2dc5261 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 8 Nov 2012 19:00:46 -0600 Subject: [PATCH 3/4] Added failing test for parsing a ? at the start of a value --- test/core/parsertests.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/core/parsertests.cpp b/test/core/parsertests.cpp index 1ff922c..2b8b5ef 100644 --- a/test/core/parsertests.cpp +++ b/test/core/parsertests.cpp @@ -16,6 +16,18 @@ namespace Test } return " no exception caught"; } + + TEST PlainScalarStartingWithQuestionMark() + { + HANDLE("foo: ?bar"); + EXPECT_DOC_START(); + EXPECT_MAP_START("?", 0); + EXPECT_SCALAR("?", 0, "foo"); + EXPECT_SCALAR("?", 0, "?bar"); + EXPECT_MAP_END(); + EXPECT_DOC_END(); + DONE(); + } } namespace { @@ -44,6 +56,7 @@ namespace Test int passed = 0; int total = 0; RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total); + RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total); std::cout << "Parser tests: " << passed << "/" << total << " passed\n"; return passed == total; From 8c517bf0fd6c627ca4dfcdc84d932928a1527ac8 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 8 Nov 2012 19:11:41 -0600 Subject: [PATCH 4/4] Fixed parsing ? when attached to a scalar --- src/exp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exp.h b/src/exp.h index 3e12aba..52bfd0a 100644 --- a/src/exp.h +++ b/src/exp.h @@ -91,7 +91,7 @@ namespace YAML return e; } inline const RegEx& Key() { - static const RegEx e = RegEx('?'); + static const RegEx e = RegEx('?') + BlankOrBreak(); return e; } inline const RegEx& KeyInFlow() {