Parser: Fix the main loop getting stuck on some signatures

In certain cases the parser could go back rather than forward after
finding a signature, causing it to find the same signature forever
until it ran out of memory.

Test cases coming later in a separate patch.

Bug: T356884
Change-Id: I8ac72b05e5e4ed45e6119c012a69708c9d8eda29
(cherry picked from commit 9db35873a4)
This commit is contained in:
Bartosz Dziewoński 2024-02-07 17:42:04 +01:00
parent 6816c15a03
commit 79c7be79e3
2 changed files with 4 additions and 2 deletions

View file

@ -922,7 +922,8 @@ class CommentParser {
$curCommentEnd = $node;
} elseif ( $node instanceof Text && ( $match = $this->findTimestamp( $node, $timestampRegexps ) ) ) {
$warnings = [];
$foundSignature = $this->findSignature( $node, $lastSigNode );
$foundSignature = $this->findSignature( $node,
$curCommentEnd === $this->rootNode ? null : $curCommentEnd );
$author = $foundSignature['username'];
$lastSigNode = $foundSignature['nodes'][0];

View file

@ -895,7 +895,8 @@ Parser.prototype.buildThreadItems = function () {
curCommentEnd = node;
} else if ( node.nodeType === Node.TEXT_NODE && ( match = this.findTimestamp( node, timestampRegexps ) ) ) {
var warnings = [];
var foundSignature = this.findSignature( node, lastSigNode );
var foundSignature = this.findSignature( node,
curCommentEnd === this.rootNode ? null : curCommentEnd );
var author = foundSignature.username;
lastSigNode = foundSignature.nodes[ 0 ];