mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions
synced 2024-11-15 11:59:54 +00:00
Make default values fall through in switch
Bug 19093. Previously {{#switch:foo|bar|#default=baz}} would behave differently from {{#switch:foo|#default|bar=baz}}, even though they'd behave identically if "#default" was replaced by "foo". I changed switchObj but not switchHook. In testing, switchObj was the only method that seemed to be used, and I didn't want to make untested changes to switchHook, so if that's used, the behavior may remain in some cases. It seems like code is duplicated between them -- whatever the difference is, that should probably be factored out. This passes all existing parser tests for #switch, of which there are none, so don't blame me if it breaks something. ;)
This commit is contained in:
parent
08bcb1bdc7
commit
6905775132
|
@ -187,7 +187,7 @@ class ExtParserFunctions {
|
|||
return '';
|
||||
}
|
||||
$primary = trim( $frame->expand( array_shift( $args ) ) );
|
||||
$found = false;
|
||||
$found = $defaultFound = false;
|
||||
$default = null;
|
||||
$lastItemHadNoEquals = false;
|
||||
$mwDefault =& MagicWord::get( 'default' );
|
||||
|
@ -209,7 +209,7 @@ class ExtParserFunctions {
|
|||
if ( $test == $primary ) {
|
||||
# Found a match, return now
|
||||
return trim( $frame->expand( $valueNode ) );
|
||||
} elseif ( $mwDefault->matchStartAndRemove( $test ) ) {
|
||||
} elseif ( $defaultFound || $mwDefault->matchStartAndRemove( $test ) ) {
|
||||
$default = $valueNode;
|
||||
} # else wrong case, continue
|
||||
}
|
||||
|
@ -220,6 +220,8 @@ class ExtParserFunctions {
|
|||
$test = trim( $frame->expand( $valueNode ) );
|
||||
if ( $test == $primary ) {
|
||||
$found = true;
|
||||
} elseif ( $mwDefault->matchStartAndRemove( $test ) ) {
|
||||
$defaultFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,3 +41,14 @@ Time test after the 2038 32-bit Apocalype
|
|||
<p>2061
|
||||
</p>
|
||||
!! end
|
||||
|
||||
!! test
|
||||
Bug 19093: Default values don't fall through in switch
|
||||
!! input
|
||||
<{{#switch: foo | bar | #default = DEF }}>
|
||||
<{{#switch: foo | #default | bar = DEF }}>
|
||||
!! result
|
||||
<p><DEF>
|
||||
<DEF>
|
||||
</p>
|
||||
!! end
|
||||
|
|
Loading…
Reference in a new issue