From f25f110e3316b2d2c1c22dd519491909af1e5d01 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Tue, 17 Feb 2026 15:38:04 +0100 Subject: [PATCH] fix: change abort when no parsing progress is made Previously, no parsing progress (detecting infinite loops) was detected by an empty Node. This falsely triggers an abort, if an empty YAML document is being parsed. Instead, we detect if progress in the parsing stream is made, by comparing token positions. As long as new tokens are being parsed (detected by position change), we assume we are not in an infinite loop. --- src/parse.cpp | 2 +- src/parser.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/parse.cpp b/src/parse.cpp index 4cfab77..262536b 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -53,7 +53,7 @@ std::vector LoadAll(std::istream& input) { Parser parser(input); while (true) { NodeBuilder builder; - if (!parser.HandleNextDocument(builder) || builder.Root().IsNull()) { + if (!parser.HandleNextDocument(builder)) { break; } docs.push_back(builder.Root()); diff --git a/src/parser.cpp b/src/parser.cpp index 04e1946..761ffd5 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -33,9 +33,24 @@ bool Parser::HandleNextDocument(EventHandler& eventHandler) { return false; } + auto oldPos = m_pScanner->peek().mark.pos; + SingleDocParser sdp(*m_pScanner, *m_pDirectives); sdp.HandleDocument(eventHandler); - return true; + + // checks if progress was made + // 1. if scanner has no more tokens, progress was made + if (m_pScanner->empty()) { + return true; + } + + // 2. if token position has changed, progress was made + auto newPos = m_pScanner->peek().mark.pos; + if (newPos != oldPos) { + return true; + } + // No progress was made, no further processing + return false; } void Parser::ParseDirectives() {