r47205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47204‎ | r47205 | r47206 >
Date:00:28, 13 February 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Fix handling of 0, 0.0, 0.00 etc in logical functions.
Modified paths:
  • /trunk/extensions/ParserFunctions/Expr.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/Expr.php
@@ -453,14 +453,24 @@
454454 if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]);
455455 $right = array_pop( $stack );
456456 $left = array_pop( $stack );
457 - // PHP seems to treat "0" and "" appropriately for this to work.
 457+
 458+ // Fix handling of 0.0, 0.00, etc
 459+ if ($hasBC) {
 460+ $right = bccompWithTolerance( $right, '0' ) != 0;
 461+ $left = bccompWithTolerance( $left, '0' ) != 0;
 462+ }
 463+
458464 $stack[] = ( $left && $right ) ? 1 : 0;
459465 break;
460466 case EXPR_OR:
461467 if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]);
462468 $right = array_pop( $stack );
463469 $left = array_pop( $stack );
464 - // PHP seems to treat "0" and "" appropriately for this to work.
 470+ // Fix handling of 0.0, 0.00, etc
 471+ if ($hasBC) {
 472+ $right = bccompWithTolerance( $right, '0' ) != 0;
 473+ $left = bccompWithTolerance( $left, '0' ) != 0;
 474+ }
465475 $stack[] = ( $left || $right ) ? 1 : 0;
466476 break;
467477 case EXPR_EQUALITY:
@@ -475,7 +485,10 @@
476486 case EXPR_NOT:
477487 if ( count( $stack ) < 1 ) throw new ExprError('missing_operand', $this->names[$op]);
478488 $arg = array_pop( $stack );
479 - // PHP seems to treat "0" and "" appropriately for this to work.
 489+ // Fix handling of 0.0, 0.00, etc
 490+ if ($haveBC) {
 491+ $arg = (bccompWithTolerance( $arg, '0' ) != 0);
 492+ }
480493 $stack[] = (!$arg) ? 1 : 0;
481494 break;
482495 case EXPR_ROUND:

Follow-up revisions

RevisionCommit summaryAuthorDate
r47311ParserFunctions: Fix undefined variable warnings introduced in r47205catrope10:08, 16 February 2009

Comments

#Comment by P.Copp (talk | contribs)   02:58, 15 February 2009

typo?

PHP Notice:  Undefined variable: hasBC in /extensions/ParserFunctions/Expr.php on line 458
PHP Notice:  Undefined variable: hasBC in /extensions/ParserFunctions/Expr.php on line 470
#Comment by Catrope (talk | contribs)   10:09, 16 February 2009

Fixed in r47311

#Comment by OverlordQ (talk | contribs)   06:30, 18 February 2009

in the power handling the result is never pushed back onto the stack which tends to break lots of things. Patch: http://www.thedarkcitadel.com/Expr.txt Against Expr.php before the changes were reverted.

Status & tagging log