phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

ErrorException when parsing header in HTTP response: Undefined offset: 1

Open cweiske opened this issue 4 months ago • 0 comments

Very seldom I get an ErrorException when using php-spo because one of the response header lines does not contain a : character. This happened ~8 times in the last 2 years.

I unfortunately do not have an example of such a HTTP response header. The relevant code in Runtime/Http/Response.php is

        foreach ($lines as $line){
            if($line != ""){
                list($k, $v) = preg_split("/[ :]/", $line,2);
                $this->Headers[$k] = $v;
            }
        }

and the error message is

ErrorException: Undefined offset: 1

It would be nice if the code would check if the header line can indeed be split before doing so.

Stack trace

ErrorException: Undefined offset: 1
#27 /vendor/vgrem/php-spo/src/Runtime/Http/Response.php(30): Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
#26 /vendor/vgrem/php-spo/src/Runtime/Http/Response.php(30): Office365\Runtime\Http\Response::getHeaders
#25 /vendor/vgrem/php-spo/src/Runtime/Http/Response.php(44): Office365\Runtime\Http\Response::validate
#24 /vendor/vgrem/php-spo/src/Runtime/Http/Response.php(15): Office365\Runtime\Http\Response::__construct
#23 /vendor/vgrem/php-spo/src/Runtime/Http/Requests.php(30): Office365\Runtime\Http\Requests::execute
#22 /vendor/vgrem/php-spo/src/Runtime/Http/Requests.php(79): Office365\Runtime\Http\Requests::post
#21 /vendor/vgrem/php-spo/src/Runtime/Auth/SamlTokenProvider.php(105): Office365\Runtime\Auth\SamlTokenProvider::acquireAuthenticationCookies
#20 /vendor/vgrem/php-spo/src/Runtime/Auth/AuthenticationContext.php(122): Office365\Runtime\Auth\AuthenticationContext::authenticateRequest
#19 /vendor/vgrem/php-spo/src/SharePoint/ClientContext.php(244): Office365\SharePoint\ClientContext::authenticateRequest
#18 /vendor/vgrem/php-spo/src/Runtime/ClientRequest.php(168): Office365\Runtime\ClientRequest::executeQueryDirect
#17 /vendor/vgrem/php-spo/src/Runtime/OData/ODataRequest.php(142): Office365\Runtime\OData\ODataRequest::executeQueryDirect
#16 /vendor/vgrem/php-spo/src/Runtime/ClientRequest.php(149): Office365\Runtime\ClientRequest::executeQuery
#15 /vendor/vgrem/php-spo/src/Runtime/ClientRuntimeContext.php(96): Office365\Runtime\ClientRuntimeContext::executeQuery

cweiske avatar Mar 04 '24 11:03 cweiske