Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void Scanner::EndStream() {
INPUT.ResetColumn();
}

InvalidateSimpleKey();
PopAllIndents();
PopAllSimpleKeys();

Expand Down
36 changes: 36 additions & 0 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,42 @@ struct ParserExceptionTestCase {
std::string expected_exception;
};

TEST(LoadNodeTest, RejectTrailingScalarInBlockMap) {
const std::vector<std::string> inputs = {
"---\nfoo: bar\nnot-a-key",
"---\nfoo: bar\nnot-a-key\n",
"---\nfoo: bar\nnot-a-key\n# A comment",
};

for (const std::string& input : inputs) {
try {
Load(input);
FAIL() << "Expected trailing scalar to be rejected, input: " << input;
} catch (const ParserException& e) {
EXPECT_EQ(ErrorMsg::END_OF_MAP, e.msg);
EXPECT_EQ(2, e.mark.line);
EXPECT_EQ(0, e.mark.column);
}
}
}

TEST(LoadNodeTest, AcceptValidDocumentsWhenPoppingSimpleKeys) {
Node scalar = Load("not-a-key");
EXPECT_TRUE(scalar.IsScalar());
EXPECT_EQ("not-a-key", scalar.as<std::string>());

Node explicit_key = Load("? key");
ASSERT_TRUE(explicit_key.IsMap());
ASSERT_EQ(1, explicit_key.size());
EXPECT_TRUE(explicit_key["key"].IsNull());

Node map = Load("foo: bar\nbaz: qux\n...");
ASSERT_TRUE(map.IsMap());
ASSERT_EQ(2, map.size());
EXPECT_EQ("bar", map["foo"].as<std::string>());
EXPECT_EQ("qux", map["baz"].as<std::string>());
}

TEST(NodeTest, IncompleteJson) {
std::vector<ParserExceptionTestCase> tests = {
{"JSON map without value", "{\"access\"", ErrorMsg::END_OF_MAP_FLOW},
Expand Down
Loading