Forbid incorrect document start (---)

Previously documents like the following was simply ignored:

    ----
    # foo
    bar: bam
This commit is contained in:
Azat Khuzhin 2024-12-22 21:13:04 +01:00
parent 76dc671573
commit 3a1070d061
2 changed files with 11 additions and 1 deletions

View File

@ -82,7 +82,7 @@ inline const RegEx& Utf8_ByteOrderMark() {
// actual tags // actual tags
inline const RegEx& DocStart() { inline const RegEx& DocStart() {
static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx()); static const RegEx e = RegEx("---");
return e; return e;
} }
inline const RegEx& DocEnd() { inline const RegEx& DocEnd() {

View File

@ -1682,5 +1682,15 @@ TEST_F(HandlerSpecTest, Ex8_22_BlockCollectionNodes) {
EXPECT_CALL(handler, OnDocumentEnd()); EXPECT_CALL(handler, OnDocumentEnd());
Parse(ex8_22); 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
} // namespace YAML } // namespace YAML