From 675951360f98f5016179e68541acbf830aedb7a1 Mon Sep 17 00:00:00 2001 From: Sergey Sannikov Date: Thu, 27 Aug 2026 17:46:39 +0400 Subject: [PATCH] Fix RESP3 double parsing returning positive INF for -inf (#1716) parseDouble() returned positive INF for the RESP3 payload ',-inf', inverting the sign. The value is reachable with protocol=3, for example ZSCORE on a member whose score is -inf. The existing infinity test asserted only is_infinite(), which cannot detect the sign inversion, so it now checks exact values. NaN payloads keep their current behavior; that is addressed separately. --- CHANGELOG.md | 1 + src/Protocol/Parser/Strategy/Resp3Strategy.php | 6 +++++- .../Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15273b70..17bec36c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added ### Changed ### Fixed +- Fixed RESP3 double parsing returning positive `INF` for `-inf` payloads (#1716) ## v3.6.0 (2026-08-14) ### Added diff --git a/src/Protocol/Parser/Strategy/Resp3Strategy.php b/src/Protocol/Parser/Strategy/Resp3Strategy.php index 83a2bfe6..7549986a 100644 --- a/src/Protocol/Parser/Strategy/Resp3Strategy.php +++ b/src/Protocol/Parser/Strategy/Resp3Strategy.php @@ -63,10 +63,14 @@ class Resp3Strategy extends Resp2Strategy */ protected function parseDouble(string $string): float { - if ($string === 'inf' || $string === '-inf') { + if ($string === 'inf') { return INF; } + if ($string === '-inf') { + return -INF; + } + return (float) $string; } diff --git a/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php b/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php index 5a42dff1..09aa58ee 100644 --- a/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php +++ b/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php @@ -60,11 +60,11 @@ class Resp3StrategyTest extends PredisTestCase * @param string $data * @return void */ - public function testParseDataReturnsFloatInfinityOnInfinityOrNegativeInfinity(string $data): void + public function testParseDataReturnsFloatInfinityOnInfinityOrNegativeInfinity(string $data, float $expectedValue): void { $actualResponse = $this->strategy->parseData($data); - $this->assertInfinite($actualResponse); + $this->assertSame($expectedValue, $actualResponse); } /** @@ -166,8 +166,8 @@ class Resp3StrategyTest extends PredisTestCase public function infinityProvider(): array { return [ - 'positive infinity' => [",inf\r\n"], - 'negative infinity' => [",-inf\r\n"], + 'positive infinity' => [",inf\r\n", INF], + 'negative infinity' => [",-inf\r\n", -INF], ]; }