ParserOutput::mergeMapStrategy - use a more robust comparison for objects

Map values can include JsonUnserializable objects, and strict
(reference) equality comparison of these objects is not going to
reflect value equality.  Serialize the values and compare strings
instead; this case should be hit very infrequently given that
rewriting the same extension data key is discouraged.

Bug: T312588
Change-Id: I942e7fa662b2f1a5e32fd55ef65eaa10a22afcfb
This commit is contained in:
C. Scott Ananian 2022-07-07 18:10:09 -04:00 committed by C. Scott Ananian
parent f5ba3b2e8e
commit 541542e588

View file

@ -2346,10 +2346,20 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
} else {
throw new InvalidArgumentException( "Unknown merge strategy $strategy" );
}
} elseif ( $a[$key] !== $bValue ) {
// Silently replace for now; in the future will first emit
// a deprecation warning, and then (later) throw.
$a[$key] = $bValue;
} else {
$valuesSame = ( $a[$key] === $bValue );
if ( ( !$valuesSame ) &&
is_object( $a[$key] ) &&
is_object( $bValue )
) {
$jsonCodec = MediaWikiServices::getInstance()->getJsonCodec();
$valuesSame = ( $jsonCodec->serialize( $a[$key] ) === $jsonCodec->serialize( $bValue ) );
}
if ( !$valuesSame ) {
// Silently replace for now; in the future will first emit
// a deprecation warning, and then (later) throw.
$a[$key] = $bValue;
}
}
}
return $a;