aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiemo Kreuz <thiemo.kreuz@wikimedia.de>2021-02-19 15:52:53 +0100
committerThiemo Kreuz <thiemo.kreuz@wikimedia.de>2021-02-19 17:04:35 +0100
commit47171f7b94c5623ce175d9544e88bc12f7819502 (patch)
treecc4f3769ce7e67dfe3a95fc75f38f67129a4ad3c
parent09d2fd495e2d2c0af5c1aee1fc99d2dd0932698d (diff)
downloadmediawikicore-47171f7b94c5623ce175d9544e88bc12f7819502.tar.gz
mediawikicore-47171f7b94c5623ce175d9544e88bc12f7819502.zip
Don't accept empty option group names for dropdown elements
When this code parses a string that looks like this: * ** A ** B It creates an option group with 2 options, but the name of the group is an empty string. This makes the OOUI DropdownInputWidget fail later. Since the empty group name is useless anyway, drop it. This makes the code behave as if the parsed string looked like this: * A * B Live example for the issue: https://el.wikipedia.org/wiki/MediaWiki:Protect-dropdown Bug: T275125 Change-Id: I780c1be27740b0ed3b35aa569b5a528112d7238f
-rw-r--r--includes/xml/Xml.php12
-rw-r--r--tests/phpunit/includes/XmlTest.php3
2 files changed, 10 insertions, 5 deletions
diff --git a/includes/xml/Xml.php b/includes/xml/Xml.php
index 4462f1a55165..f07e35859444 100644
--- a/includes/xml/Xml.php
+++ b/includes/xml/Xml.php
@@ -557,10 +557,14 @@ class Xml {
} elseif ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) {
# A new group is starting...
$value = trim( substr( $value, 1 ) );
- # Do not use the value for 'other' as option group - T251351
- $optgroup = isset( $params['other'] ) && $params['other'] === $value
- ? false
- : $value;
+ if ( $value !== '' &&
+ // Do not use the value for 'other' as option group - T251351
+ ( !isset( $params['other'] ) || $value !== $params['other'] )
+ ) {
+ $optgroup = $value;
+ } else {
+ $optgroup = false;
+ }
} elseif ( substr( $value, 0, 2 ) == '**' ) {
# groupmember
$opt = trim( substr( $value, 2 ) );
diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php
index 8ff2afbecabb..3f0ee0121283 100644
--- a/tests/phpunit/includes/XmlTest.php
+++ b/tests/phpunit/includes/XmlTest.php
@@ -375,6 +375,7 @@ class XmlTest extends MediaWikiIntegrationTestCase {
$this->assertEquals(
[
'other reasons' => 'other',
+ 'Empty group item' => 'Empty group item',
'Foo' => [
'Foo 1' => 'Foo 1',
'Example' => 'Example',
@@ -384,7 +385,7 @@ class XmlTest extends MediaWikiIntegrationTestCase {
],
],
Xml::listDropDownOptions(
- "* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
+ "*\n** Empty group item\n* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
[ 'other' => 'other reasons' ]
)
);