Skip to content

Commit

Permalink
Assert curl data are always fully serialized before request
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored and robocoder committed Apr 19, 2022
1 parent b5b18bd commit c893a53
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/WebDriver/AbstractWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
$url .= '/' . $parameters;
}

$this->assertNonObjectParameters($parameters);

list($rawResult, $info) = ServiceFactory::getInstance()->getService('service.curl')->execute($requestMethod, $url, $parameters, $extraOptions);

$httpCode = $info['http_code'];
Expand Down Expand Up @@ -197,6 +199,32 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
);
}

/**
* @param mixed $parameters
*/
private function assertNonObjectParameters($parameters)
{
if ($parameters === null || is_scalar($parameters)) {
return;
}

if (is_array($parameters)) {
foreach ($parameters as $value) {
$this->assertNonObjectParameters($value);
}

return;
}

throw WebDriverException::factory(
WebDriverException::UNEXPECTED_PARAMETERS,
sprintf(
"Unable to serialize non-scalar type %s",
is_object($parameters) ? get_class($parameters) : gettype($parameters)
)
);
}

/**
* Magic method that maps calls to class methods to execute WebDriver commands
*
Expand Down

0 comments on commit c893a53

Please sign in to comment.