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

This commit is contained in:
Jesse Beder
2013-04-13 18:21:06 -05:00
parent e0ae477b8f
commit 2375f2c66b
2 changed files with 19 additions and 0 deletions

View File

@@ -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())

View File

@@ -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
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;