Make ParserOptions::isSafeToCache more robust

Bug: T273120
Change-Id: I516133d07d9ff4d7930de68b88ed4b40ca1c6150
This commit is contained in:
Petr Pchelko 2021-01-27 18:33:35 -06:00
parent 1fb76fefbb
commit b964bd2e8d
2 changed files with 9 additions and 8 deletions

View file

@ -1470,9 +1470,8 @@ class ParserOptions {
$usedOptions = $usedOptions ?? array_keys( $this->options );
foreach ( $usedOptions as $option ) {
if ( empty( self::$inCacheKey[$option] ) && empty( self::$callbacks[$option] ) ) {
$value = $this->options[$option] ?? null;
$v = $this->optionToString( $value );
$d = $this->optionToString( $defaults[$option] );
$v = $this->optionToString( $this->options[$option] ?? null );
$d = $this->optionToString( $defaults[$option] ?? null );
if ( $v !== $d ) {
return false;
}

View file

@ -110,14 +110,14 @@ class ParserOptionsTest extends MediaWikiLangTestCase {
* @dataProvider provideIsSafeToCache
* @param bool $expect Expected value
* @param array $options Options to set
* @param array|null $userOptions
* @param array|null $usedOptions
*/
public function testIsSafeToCache( bool $expect, array $options, array $userOptions = null ) {
public function testIsSafeToCache( bool $expect, array $options, array $usedOptions = null ) {
$popt = ParserOptions::newCanonical( 'canonical' );
foreach ( $options as $name => $value ) {
$popt->setOption( $name, $value );
}
$this->assertSame( $expect, $popt->isSafeToCache() );
$this->assertSame( $expect, $popt->isSafeToCache( $usedOptions ) );
}
public static function provideIsSafeToCache() {
@ -144,12 +144,14 @@ class ParserOptionsTest extends MediaWikiLangTestCase {
'Non-in-key options are not ok, used' => [ false, [
'removeComments' => false,
], [ 'removeComments' ] ],
'Non-in-key options are ok if other used' => [ false, [
'Non-in-key options are ok if other used' => [ true, [
'removeComments' => false,
], [ 'thumbsize' ] ],
'Non-in-key options are ok if nothing used' => [ false, [
'Non-in-key options are ok if nothing used' => [ true, [
'removeComments' => false,
], [] ],
'Unknown used options do not crash' => [ true, [
], [ 'unknown' ] ],
'Non-in-key options are not ok (2)' => [ false, [
'wrapclass' => 'foobar',
] ],