Correct the + symbol processing when sorting results in the API controllers (#1322)

This commit is contained in:
Alex Tselegidis 2023-01-23 07:54:06 +01:00
parent c7371090ba
commit 7343389f7b
1 changed files with 4 additions and 3 deletions

View File

@ -216,15 +216,16 @@ class Api {
{
$api_field = substr($sort_token, 1);
$db_field = $this->model->db_field($api_field);
$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_operator = '+';
$api_field = $sort_token;
}
$db_field = $this->model->db_field($api_field);
$direction = $direction_operator === '-' ? 'DESC' : 'ASC';
$order_by[] = $db_field . ' ' . $direction;