Commit 2375f2c6 by Jesse Beder

Fix bug where the string "null" (without quotes) is deserialized as a string, instead of null.

parent e0ae477b
...@@ -75,6 +75,12 @@ namespace YAML ...@@ -75,6 +75,12 @@ namespace YAML
ParseProperties(tag, anchor); ParseProperties(tag, anchor);
const Token& token = m_scanner.peek(); const Token& token = m_scanner.peek();
if(token.type == Token::PLAIN_SCALAR && token.value == "null") {
eventHandler.OnNull(mark, anchor);
m_scanner.pop();
return;
}
// add non-specific tags // add non-specific tags
if(tag.empty()) if(tag.empty())
......
...@@ -28,6 +28,18 @@ namespace Test ...@@ -28,6 +28,18 @@ namespace Test
EXPECT_DOC_END(); EXPECT_DOC_END();
DONE(); DONE();
} }
TEST NullStringScalar()
{
HANDLE("foo: null");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
EXPECT_SCALAR("?", 0, "foo");
EXPECT_NULL(0);
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
} }
namespace { namespace {
...@@ -57,6 +69,7 @@ namespace Test ...@@ -57,6 +69,7 @@ namespace Test
int total = 0; int total = 0;
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total); RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total); RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
RunParserTest(&Parser::NullStringScalar, "Null string scalar", passed, total);
std::cout << "Parser tests: " << passed << "/" << total << " passed\n"; std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
return passed == total; return passed == total;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment