[WebSocket] Prevent division by 0 in Hixie handshake

This commit is contained in:
Chris Boden 2013-03-31 14:16:40 -04:00
parent 3030c81f03
commit 92f3844a53
2 changed files with 5 additions and 0 deletions

View File

@ -103,6 +103,10 @@ class Hixie76 implements VersionInterface {
}
public function generateKeyNumber($key) {
if (0 === substr_count($key, ' ')) {
return 0;
}
return preg_replace('[\D]', '', $key) / substr_count($key, ' ');
}

View File

@ -32,6 +32,7 @@ class Hixie76Test extends \PHPUnit_Framework_TestCase {
return array(
array(179922739, '17 9 G`ZD9 2 2b 7X 3 /r90')
, array(906585445, '3e6b263 4 17 80')
, array(0, '3e6b26341780')
);
}