Changed search order parsing to be more strict
This commit is contained in:
parent
61e95ac708
commit
52d44284fb
2 changed files with 30 additions and 3 deletions
|
@ -96,9 +96,22 @@ abstract class AbstractSearchParser
|
|||
{
|
||||
$token = preg_split('/,|\s+/', $token);
|
||||
$orderToken = $token[0];
|
||||
$orderDir = (count($token) === 2 and $token[1] === 'asc')
|
||||
? \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC
|
||||
: \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC;
|
||||
|
||||
if (count($token) === 1)
|
||||
{
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC;
|
||||
}
|
||||
elseif (count($token) === 2)
|
||||
{
|
||||
if ($token[1] === 'desc')
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC;
|
||||
elseif ($token[1] === 'asc')
|
||||
$orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC;
|
||||
else
|
||||
throw new \Exception('Wrong search order direction');
|
||||
}
|
||||
else
|
||||
throw new \Exception('Wrong search order token');
|
||||
|
||||
$orderColumn = $this->getOrderColumn($orderToken);
|
||||
if ($orderColumn === null)
|
||||
|
|
|
@ -24,6 +24,20 @@ class UserSearchParserTest extends AbstractTestCase
|
|||
$this->assertEquals([UserFilter::ORDER_NAME => UserFilter::ORDER_ASC], $filter->getOrder());
|
||||
}
|
||||
|
||||
public function testInvalidOrder()
|
||||
{
|
||||
$this->inputReader->order = 'invalid,desc';
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
}
|
||||
|
||||
public function testInvalidOrderDirection()
|
||||
{
|
||||
$this->inputReader->order = 'name,invalid';
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
}
|
||||
|
||||
public function testParamOrder()
|
||||
{
|
||||
$this->inputReader->order = 'name,desc';
|
||||
|
|
Loading…
Reference in a new issue