mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2026-02-19 14:46:28 +00:00
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:
committed by
Jesse Beder
parent
f3f123cea0
commit
f25f110e33
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user