Skip to content

Commit 834d2b3

Browse files
Fix HMGET where hash fields have an integer prefix
We were incorrectly ignoring errors when calling `is_numeric_string`, meaning we would truncate hash fields that had integer prefixes. ```php $redis->hmget('hash', ['123notaninteger']); // Would actually execute: // HMGET hash 123 ``` Fixes #2731
1 parent 2f2d811 commit 834d2b3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

redis_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2688,7 +2688,7 @@ static inline zval *coerce_hash_field(zval *zv, zval *aux) {
26882688

26892689
if (UNEXPECTED(Z_TYPE_P(zv) == IS_STRING &&
26902690
is_numeric_string(Z_STRVAL_P(zv),
2691-
Z_STRLEN_P(zv), &lv, NULL, 1) == IS_LONG))
2691+
Z_STRLEN_P(zv), &lv, NULL, 0) == IS_LONG))
26922692
{
26932693
ZVAL_LONG(aux, lv);
26942694
return aux;

tests/RedisTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,24 @@ public function testHashes() {
33953395
}
33963396
}
33973397

3398+
/* Regression test for GitHub issue 2731 */
3399+
public function testNumericPrefixHashFields() {
3400+
$hash = [
3401+
'86deaeb05e3f7760b67e92897a1325e0fdd8618d' => 'one',
3402+
'-86deaeb05e3f7760b67e92897a1325e0fdd8618d' => 'two',
3403+
12345 => 'a_real_number',
3404+
-12345 => 'a_negative_real_number',
3405+
];
3406+
3407+
$this->assertIsInt($this->redis->del('hash'));
3408+
$this->assertTrue($this->redis->hmset('hash', $hash));
3409+
3410+
$res = $this->redis->hmget('hash', array_keys($hash));
3411+
3412+
// The keys from our local variable and res should be equal
3413+
$this->assertEqualsCanonicalizing(array_keys($hash), array_keys($res));
3414+
}
3415+
33983416
public function testHRandField() {
33993417
if (version_compare($this->version, '6.2.0') < 0)
34003418
$this->MarkTestSkipped();

0 commit comments

Comments
 (0)