Skip to content

Commit

Permalink
Forbid incorrect document start (---)
Browse files Browse the repository at this point in the history
Previously documents like the following was simply ignored:

    ----
    # foo
    bar: bam
  • Loading branch information
azat committed Dec 22, 2024
1 parent 76dc671 commit 3a1070d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/exp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline const RegEx& Utf8_ByteOrderMark() {
// actual tags

inline const RegEx& DocStart() {
static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
static const RegEx e = RegEx("---");
return e;
}
inline const RegEx& DocEnd() {
Expand Down
10 changes: 10 additions & 0 deletions test/integration/handler_spec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,5 +1682,15 @@ TEST_F(HandlerSpecTest, Ex8_22_BlockCollectionNodes) {
EXPECT_CALL(handler, OnDocumentEnd());
Parse(ex8_22);
}

TEST_F(HandlerSpecTest, InvalidDocStart1) {
EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse("----\nbaz: 1"),
ErrorMsg::BLOCK_ENTRY);
}
TEST_F(HandlerSpecTest, InvalidDocStart2) {
EXPECT_THROW_PARSER_EXCEPTION(IgnoreParse("----\n# foo\nbaz: 1"),
ErrorMsg::BLOCK_ENTRY);
}

} // namespace
} // namespace YAML

0 comments on commit 3a1070d

Please sign in to comment.