From 3a1070d0619bea942f6850474ddfb93f6a19ba77 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 22 Dec 2024 21:13:04 +0100 Subject: [PATCH] Forbid incorrect document start (---) Previously documents like the following was simply ignored: ---- # foo bar: bam --- src/exp.h | 2 +- test/integration/handler_spec_test.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/exp.h b/src/exp.h index c8837f0f8..a44718eb2 100644 --- a/src/exp.h +++ b/src/exp.h @@ -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() { diff --git a/test/integration/handler_spec_test.cpp b/test/integration/handler_spec_test.cpp index 8cba9023d..cdc004683 100644 --- a/test/integration/handler_spec_test.cpp +++ b/test/integration/handler_spec_test.cpp @@ -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