diff --git a/src/Cite.php b/src/Cite.php index 6d1c98786..a6dce9512 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -193,11 +193,16 @@ class Cite { * parsed or default values. Missing attributes will be `null`. */ private function parseArguments( array $argv, array $allowedAttributes ): StatusValue { - $maxCount = count( $allowedAttributes ); + $expected = count( $allowedAttributes ); $allValues = array_merge( array_fill_keys( $allowedAttributes, null ), $argv ); - $status = StatusValue::newGood( array_slice( $allValues, 0, $maxCount ) ); + if ( isset( $allValues['dir'] ) ) { + // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal False positive + $allValues['dir'] = strtolower( $allValues['dir'] ); + } - if ( count( $allValues ) > $maxCount ) { + $status = StatusValue::newGood( array_slice( $allValues, 0, $expected ) ); + + if ( count( $allValues ) > $expected ) { // A must have a name (can be null), but can't have one $status->fatal( in_array( 'name', $allowedAttributes, true ) ? 'cite_error_ref_too_many_keys' diff --git a/src/ReferencesFormatter.php b/src/ReferencesFormatter.php index 0ce345ef6..f3dccabd3 100644 --- a/src/ReferencesFormatter.php +++ b/src/ReferencesFormatter.php @@ -154,11 +154,10 @@ class ReferencesFormatter { $extraAttributes = ''; if ( isset( $val['dir'] ) ) { - $dir = strtolower( $val['dir'] ); // The following classes are generated here: // * mw-cite-dir-ltr // * mw-cite-dir-rtl - $extraAttributes = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $dir ] ); + $extraAttributes = Html::expandAttributes( [ 'class' => 'mw-cite-dir-' . $val['dir'] ] ); } // Special case for an incomplete follow="…". This is valid e.g. in the Page:… namespace on diff --git a/src/Validator.php b/src/Validator.php index fae896b1b..3bb6f0f9c 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -76,7 +76,7 @@ class Validator { return StatusValue::newFatal( 'cite_error_ref_follow_conflicts' ); } - if ( $dir !== null && !in_array( strtolower( $dir ), [ 'ltr', 'rtl' ], true ) ) { + if ( $dir !== null && $dir !== 'rtl' && $dir !== 'ltr' ) { return StatusValue::newFatal( 'cite_error_ref_invalid_dir', $dir ); } diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt index 191ac936c..849641ccf 100644 --- a/tests/parser/citeParserTests.txt +++ b/tests/parser/citeParserTests.txt @@ -1324,7 +1324,7 @@ T202593: Conflicting dir attributes with the full ref first !! test T202593: Identical dir attributes are pointless, but should not generate an error !! wikitext - + abc !! html/php diff --git a/tests/phpunit/integration/CiteTest.php b/tests/phpunit/integration/CiteTest.php index 17df73872..fb1234663 100644 --- a/tests/phpunit/integration/CiteTest.php +++ b/tests/phpunit/integration/CiteTest.php @@ -58,7 +58,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase { 'attributes' => [ 'dir' => 'invalid' ], 'expectedValue' => [ 'invalid', null, null, null, null ] ], [ - 'attributes' => [ 'dir' => 'rtl' ], + 'attributes' => [ 'dir' => 'RTL' ], 'expectedValue' => [ 'rtl', null, null, null, null ] ], [ 'attributes' => [ 'follow' => 'f' ], diff --git a/tests/phpunit/integration/ValidatorTest.php b/tests/phpunit/integration/ValidatorTest.php index f45f743ef..34f2ca6af 100644 --- a/tests/phpunit/integration/ValidatorTest.php +++ b/tests/phpunit/integration/ValidatorTest.php @@ -259,7 +259,7 @@ class ValidatorTest extends \MediaWikiIntegrationTestCase { 'name' => 'n', 'extends' => null, 'follow' => null, - 'dir' => 'RTL', + 'dir' => 'rtl', 'expected' => null, ], 'Bad dir' => [