r63906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63905‎ | r63906 | r63907 >
Date:11:35, 18 March 2010
Author:ialex
Status:ok
Tags:
Comment:
* (bug 22866) Cast returned value to numeric if possible to do the check since ExprParser::doExpression() returns a string, this was causing some bugs since "-0" (string) converted to boolean is "true"
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php
@@ -67,7 +67,11 @@
6868
6969 function ifexpr( &$parser, $expr = '', $then = '', $else = '' ) {
7070 try{
71 - if($this->getExprParser()->doExpression( $expr )) {
 71+ $ret = $this->getExprParser()->doExpression( $expr );
 72+ if ( is_numeric( $ret ) ) {
 73+ $ret = floatval( $ret );
 74+ }
 75+ if( $ret ) {
7276 return $then;
7377 } else {
7478 return $else;

Follow-up revisions

RevisionCommit summaryAuthorDate
r63913Follow-up r63906: add test caseialex16:31, 18 March 2010

Status & tagging log