Skip to content

Commit

Permalink
Fix reading empty token stack with a node with properties but no scalar.
Browse files Browse the repository at this point in the history
E.g. `!2`.
  • Loading branch information
jbeder committed Jan 21, 2020
1 parent 3dca866 commit c946011
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/singledocparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
if (!anchor_name.empty())
eventHandler.OnAnchor(mark, anchor_name);

// after parsing properties, an empty node is again a possibility
if (m_scanner.empty()) {
eventHandler.OnNull(mark, anchor);
return;
}

const Token& token = m_scanner.peek();

if (token.type == Token::PLAIN_SCALAR && IsNullString(token.value)) {
Expand Down
5 changes: 5 additions & 0 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,10 @@ TEST(NodeTest, LoadTagWithParenthesis) {
EXPECT_EQ(node.as<std::string>(), "foo");
}

TEST(NodeTest, LoadTagWithNullScalar) {
Node node = Load("!2");
EXPECT_TRUE(node.IsNull());
}

} // namespace
} // namespace YAML

0 comments on commit c946011

Please sign in to comment.