r111248 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111247‎ | r111248 | r111249 >
Date:17:52, 11 February 2012
Author:mkroetzsch
Status:deferred
Tags:
Comment:
avoid 0 as conversion factor; Bug 32594
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Quantity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Quantity.php
@@ -27,6 +27,7 @@
2828 $this->initConversionData();
2929 if ( array_key_exists( $unit, $this->m_unitids ) ) {
3030 $this->m_unitin = $this->m_unitids[$unit];
 31+ assert( '$this->m_unitfactors[$this->m_unitin] != 0 /* Should be filtered by initConversionData() */' );
3132 $this->m_dataitem = new SMWDINumber( $number / $this->m_unitfactors[$this->m_unitin], $this->m_typeid );
3233 return true;
3334 } else { // unsupported unit
@@ -132,7 +133,8 @@
133134 $number = $unit = '';
134135 foreach ( $factors as $di ) {
135136 if ( ( $di->getDIType() !== SMWDataItem::TYPE_STRING ) ||
136 - ( SMWNumberValue::parseNumberValue( $di->getString(), $number, $unit ) != 0 ) ) {
 137+ ( SMWNumberValue::parseNumberValue( $di->getString(), $number, $unit ) != 0 ) ||
 138+ ( $number == 0 ) ) {
137139 continue; // ignore corrupted data and bogus inputs
138140 }
139141 $unit_aliases = preg_split( '/\s*,\s*/u', $unit );