diff --git a/src/SDK/Common/Export/Http/PsrUtils.php b/src/SDK/Common/Export/Http/PsrUtils.php index 79aaee832..1639ba471 100644 --- a/src/SDK/Common/Export/Http/PsrUtils.php +++ b/src/SDK/Common/Export/Http/PsrUtils.php @@ -91,6 +91,10 @@ public static function encode(string $value, array $encodings, ?array &$appliedE */ public static function decode(string $value, array $encodings): string { + if ($value === '') { + return $value; + } + for ($i = count($encodings); --$i >= 0;) { if (strcasecmp($encodings[$i], 'identity') === 0) { continue; diff --git a/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php b/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php index 744426719..dab731d93 100644 --- a/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php +++ b/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php @@ -97,7 +97,7 @@ public function test_send_decodes_response_body(): void public function test_send_decode_unknown_encoding_returns_error(): void { - $this->client->expects($this->once())->method('sendRequest')->willReturn(new Response(200, ['Content-Encoding' => 'invalid'], '')); + $this->client->expects($this->once())->method('sendRequest')->willReturn(new Response(200, ['Content-Encoding' => 'invalid'], 'foo')); $transport = $this->factory->create('http://localhost', 'text/plain'); $response = $transport->send(''); diff --git a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php index 6b018fbd3..c47430eef 100644 --- a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php +++ b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php @@ -89,7 +89,12 @@ public function test_decode_stream_unknown_encoding(): void { $this->expectException(UnexpectedValueException::class); - PsrUtils::decode('', ['invalid']); + PsrUtils::decode('foo', ['invalid']); + } + + public function test_decode_empty_value(): void + { + $this->assertSame('', PsrUtils::decode('', ['gzip'])); } #[DataProvider('compressionProvider')]