Added validation to the sort direction value

This commit is contained in:
Alex Tselegidis 2021-11-06 13:30:12 +01:00
parent 01dfdf22f1
commit 2406eefd39

View file

@ -253,7 +253,14 @@ class Api {
$db_field = $this->model->db_field($api_field); $db_field = $this->model->db_field($api_field);
$direction = substr($sort_token, 0, 1) === '-' ? 'DESC' : 'ASC'; $direction_operator = substr($sort_token, 0, 1);
if ( ! in_array($direction_operator, ['-', '+']))
{
throw new InvalidArgumentException('Invalid sort direction operator provided (expected "-" or "+"): ' . $direction_operator);
}
$direction = $direction_operator === '-' ? 'DESC' : 'ASC';
$order_by[] = $db_field . ' ' . $direction; $order_by[] = $db_field . ' ' . $direction;
} }