From 02fb17d10295afe0b52dca5639d36eb5249fdf23 Mon Sep 17 00:00:00 2001 From: sbailey Date: Wed, 21 Oct 2020 15:46:06 -0700 Subject: [PATCH] Refs in group with no * Generating error message in data-mw in affected refs * Cite test validates correctness of adding error to afflicted refs * Autogenerated references aren't considered erroneous (the extension to the legacy parser also generates them) and are not suppressed when serializing because apparently that's the behaviour Parsoid clients want. However, in this patch we're marking up autogenerated references *with group attributes* as errors (the legacy extension doesn't generate them at all) and are choosing to suppress them when serializing since we considered them an error while parsing and don't want them to persist in the content. Bug: T51538 Change-Id: Ia651b10449dc41c2cb439b33a361e8c8e482f502 --- src/Parsoid/References.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 295fd1b2b..f5ef62749 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -81,7 +81,7 @@ class References extends ExtensionTagHandler { ] ); $dataMw = (object)[ 'name' => 'references', - 'attrs' => new stdClass, + 'attrs' => new stdClass ]; // Dont emit empty keys if ( $refsOpts['group'] ) { @@ -458,6 +458,21 @@ class References extends ExtensionTagHandler { ): void { $doc = $node->ownerDocument; foreach ( $refsData->getRefGroups() as $groupName => $refsGroup ) { + if ( $groupName !== "" ) { + // Mark all refs that are part of a group that is missing + foreach ( $refsGroup->indexByName as $ref ) { + foreach ( $ref->nodes as $linkBack ) { + DOMUtils::addTypeOf( $linkBack, 'mw:Error' ); + $dmw = DOMDataUtils::getDataMw( $linkBack ); + $errs = [ [ 'key' => 'cite_error_group_refs_without_references' ] ]; + if ( is_array( $dmw->errors ?? null ) ) { + $errs = array_merge( $dmw->errors, $errs ); + } + $dmw->errors = $errs; + } + } + } + $domFragment = $doc->createDocumentFragment(); $frag = self::createReferences( $extApi, @@ -643,7 +658,8 @@ class References extends ExtensionTagHandler { ParsoidExtensionAPI $extApi, DOMElement $node, bool $wrapperUnmodified ) { $dataMw = DOMDataUtils::getDataMw( $node ); - if ( !empty( $dataMw->autoGenerated ) && $extApi->rtTestMode() ) { + if ( !empty( $dataMw->autoGenerated ) && ( ( $dataMw->attrs->group ?? '' ) !== '' + || $extApi->rtTestMode() ) ) { // Eliminate auto-inserted noise in rt-testing return ''; } else {