From: Aaron Schulz Date: Mon, 13 May 2013 18:20:11 +0000 (-0700) Subject: Strengthened validation for HashRing a bit. X-Git-Tag: 1.31.0-rc.0~19689^2 X-Git-Url: http://git.cyclocoop.org/%22.%24redirect_annul.%22?a=commitdiff_plain;h=9d1cd9ad55b47dfe3514d4b31e47708fb98a304b;p=lhc%2Fweb%2Fwiklou.git Strengthened validation for HashRing a bit. Change-Id: Ib0331662c785d806063ca730905dd88b6545d8f0 --- diff --git a/includes/HashRing.php b/includes/HashRing.php index 227a287de8..73a38af949 100644 --- a/includes/HashRing.php +++ b/includes/HashRing.php @@ -36,8 +36,8 @@ class HashRing { * @param array $map (location => weight) */ public function __construct( array $map ) { - $sum = array_sum( $map ); - if ( !count( $map ) || $sum <= 0 ) { + $map = array_filter( $map, function( $w ) { return $w > 0; } ); + if ( !count( $map ) ) { throw new MWException( "Ring is empty or all weights are zero." ); } // Sort the locations based on the hash of their names