Fix wrong CRC16 calculated on integer value.

Closes #450.
This commit is contained in:
Daniele Alessandri
2017-07-12 11:06:53 +02:00
parent d77b77bbd9
commit 343afd312a
3 changed files with 20 additions and 0 deletions
+7
View File
@@ -1,3 +1,10 @@
v1.1.2 (2017-xx-xx)
================================================================================
- __FIX__: pure CRC16 implementation failed to calculate the correct hash when
the input value passed to the `hash()` method is an integer (PR #450).
v1.1.1 (2016-06-16)
================================================================================
+2
View File
@@ -61,6 +61,8 @@ class CRC16 implements HashGeneratorInterface
// CRC-CCITT-16 algorithm
$crc = 0;
$CCITT_16 = self::$CCITT_16;
$value = (string) $value;
$strlen = strlen($value);
for ($i = 0; $i < $strlen; ++$i) {
+11
View File
@@ -36,4 +36,15 @@ class CRC16Test extends PredisTestCase
$this->assertSame(25343, $crc16->hash('key:008'));
$this->assertSame(29406, $crc16->hash('key:009'));
}
/**
* @group disconnected
*/
public function testHashGenerationWithIntegerValues()
{
$crc16 = new CRC16();
$this->assertSame(13907, $crc16->hash(0));
$this->assertSame(55177, $crc16->hash(1234));
}
}