zendframework / zend-http

Http component from Zend Framework
BSD 3-Clause "New" or "Revised" License
134 stars 85 forks source link

Bad logic while checking if timeouts are numeric #169

Closed javabudd closed 5 years ago

javabudd commented 5 years ago

There was new logic added to the Client and Socket adapters to apply an integer/numeric check (https://github.com/zendframework/zend-http/commit/5b36ca3daf51a02763c409a291f0e7c79b9828cc, https://github.com/zendframework/zend-http/commit/4dc2c305864986624ec7156962015ed76ba54f48) that is not working as expected.

if ($connectTimeout !== null && (! is_int($connectTimeout) || ! is_numeric($connectTimeout))) {
                throw new AdapterException\InvalidArgumentException(sprintf(
                    'integer or numeric string expected, got %s',
                    gettype($connectTimeout)
                ));
            }

If $connectTimeout is a numeric string, ! is_int($connectTimeout) will return true and the exception will be thrown without is_numeric being called.

Code to reproduce the issue

$client = new \Zend\Http\Client();
$client->setOptions(['timeout' => '20']);

$request = new \Zend\Http\Request();
$client->dispatch($request);

Expected results

Timeout should be validated properly since it's a numeric string.

Actual results

Exception is thrown integer or numeric string expected, got string.

kmwalke commented 5 years ago

My team ran into this exact issue.

michalbundyra commented 5 years ago

Please see #168