From 9d1cd9ad55b47dfe3514d4b31e47708fb98a304b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 13 May 2013 11:20:11 -0700 Subject: [PATCH] Strengthened validation for HashRing a bit. Change-Id: Ib0331662c785d806063ca730905dd88b6545d8f0 --- includes/HashRing.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.20.1