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.
This commit is contained in:
Simon Gene Gottlieb
2026-02-17 15:38:04 +01:00
committed by Jesse Beder
parent f3f123cea0
commit f25f110e33
2 changed files with 17 additions and 2 deletions

View File

@@ -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() {