Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent HttpUtil::parseResponse() from emitting PHP Notice Undefined offset 1 #302

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/VCR/Util/HttpUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function parseResponse(string $response): array
{
$response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $response);

[$rawHeader, $rawBody] = explode("\r\n\r\n", $response, 2);
[$rawHeader, $rawBody] = array_pad(explode("\r\n\r\n", $response, 2), 2, '');

// Parse headers and status.
$headers = self::parseRawHeader($rawHeader);
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Util/HttpUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
$this->assertEquals($expectedHeaders, $headers);
}

public function testParseResponseNull() : void
{
$raw = null;
[$status, $headers, $body] = HttpUtil::parseResponse($raw);

Check failure on line 50 in tests/Unit/Util/HttpUtilTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $response of static method VCR\Util\HttpUtil::parseResponse() expects string, null given.

$expectedHeaders = [];
$this->assertEquals(null, $status);
$this->assertEquals(null, $body);
$this->assertEquals($expectedHeaders, $headers);
}


public function testParseContinuePlusResponse(): void
{
$raw = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
Expand Down