From d3f85b16c5ea4315d7cda3fe9e48fa45321fd770 Mon Sep 17 00:00:00 2001
From: Isabelle Hurbain-Palatin
Date: Mon, 18 Nov 2024 13:54:56 +0100
Subject: [PATCH] Only display the first occurrence of an error
It can happen that an error is reported multiple times for a given
reference. In this case, we only display one.
We still display different errors if a reference contains multiple
different errors. This behaviour is differs from the legacy parser's
(so, in this case, we add the category
cite-tracking-category-cite-diffing-error), but not from the legacy
parser's desired behaviour, as hinted by the various comments and TODO
in this area.
Bug: T380153
Change-Id: I9b3d5cbd086fc72c66a2afbae8f92297681989ce
---
src/Parsoid/RefGroup.php | 15 ++++++++++++++-
tests/parser/citeParserTests.txt | 4 ++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/Parsoid/RefGroup.php b/src/Parsoid/RefGroup.php
index 328ae7cd4..5e4bc80ca 100644
--- a/src/Parsoid/RefGroup.php
+++ b/src/Parsoid/RefGroup.php
@@ -84,11 +84,24 @@ class RefGroup {
}
$li->appendChild( $reftextSpan );
+ // It seems counter-productive to go through hoops to not display all the errors considering that rendering
+ // only the first one is considered deprecated in the legacy code. However, displaying the same error
+ // multiple times for the same reference is also useless.
+ // Hence, we avoid displaying the same error multiple times, and keep count of multiple errors under this
+ // constraint; if we still display multiple errors where the legacy parser would only display one, we add
+ // the page to the cite-tracking-category-cite-diffing-error category.
+ $reported = [];
+ $errorCount = 0;
foreach ( $ref->nodes as $node ) {
foreach ( DOMDataUtils::getDataMw( $node )->errors ?? [] as $error ) {
+ if ( in_array( $error, $reported ) ) {
+ continue;
+ }
+ $reported[] = $error;
+ $errorCount++;
$errorFragment = ErrorUtils::renderParsoidError( $extApi, $error->key, $error->params );
$li->appendChild( $errorFragment );
- if ( ErrorUtils::isDiffingError( $error->key ) ) {
+ if ( ErrorUtils::isDiffingError( $error->key ) || $errorCount > 1 ) {
$extApi->addTrackingCategory( 'cite-tracking-category-cite-diffing-error' );
}
}
diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt
index 4d61bb300..dd856948f 100644
--- a/tests/parser/citeParserTests.txt
+++ b/tests/parser/citeParserTests.txt
@@ -2035,12 +2035,12 @@ BETA[NOTES 1]
TWO[NOTES 1]
-
+
THREE[NOTES 1]
FOUR[NOTES 2]
FIVE[NOTES 2]
SIX[1]
-
+
SEVEN[NOTES 1]
EIGHT[NOTES 2]