Ensure error handling for invalid json_decode output by adding array validation checks across routes, traits, and response methods. Replace echo statements with standardized response error handling in module_config_t.
This commit is contained in:
@@ -529,11 +529,9 @@ trait route_t
|
||||
public function fromRequest(string $name): ?string
|
||||
{
|
||||
// If the $_POST variable is set, return the value from the POST variable, otherwise return the value from the query string
|
||||
if (isset($_POST)) {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
if (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
if (is_array($data) && isset($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
return (isset($_POST[$name])) ? $_POST[$name] : $this->fromQuery($name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user