From dacfb65c0011542c2a2076b1f291950eaa6f3393 Mon Sep 17 00:00:00 2001 From: "yuxaoxao@qq.com" Date: Sun, 13 Jul 2025 19:44:16 +0800 Subject: [PATCH] fix zero value conversion error --- src/Core/Value.php | 2 +- tests/CompressJsonBaseTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Core/Value.php b/src/Core/Value.php index 117c01c..2bb8b0b 100644 --- a/src/Core/Value.php +++ b/src/Core/Value.php @@ -47,7 +47,7 @@ public function decode($values): mixed } //$value = (string) $value; if ($this->isNumeric()) { - return $this; + return $this->value; } else if ($this->isString()) { $prefix = $this->getStringPrefix(); diff --git a/tests/CompressJsonBaseTest.php b/tests/CompressJsonBaseTest.php index acd1c49..9cce0d7 100644 --- a/tests/CompressJsonBaseTest.php +++ b/tests/CompressJsonBaseTest.php @@ -130,4 +130,17 @@ public function testSecondValueAsNumericalString() // Assert $this->assertEquals($data, $decompressed); } + + public function testNumericalStringDecompressJson() + { + //raw json + $rawJson = '["0"]'; + //compress-json.js generated compressed json + $compressedJson = '[["0","a|0"],"1"]'; + $data=json_decode($rawJson,true); + $decompressed = Compressor::create() + ->decompressJson($compressedJson); + // Assert + $this->assertSame($data, $decompressed); + } } \ No newline at end of file