Skip to content

Commit

Permalink
Merge branch 'release/3.7.40' of https://github.com/craftcms/cms into…
Browse files Browse the repository at this point in the history
… 4.0

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
brandonkelly committed May 2, 2022
2 parents 29b6fda + aca7413 commit f164ad2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/gql/ArgumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ public function prepareArguments(array $arguments): array
{
$orderBy = $arguments['orderBy'] ?? null;
if ($orderBy) {
if (StringHelper::containsAny($orderBy, ['(', ')'])) {
throw new GqlException('Illegal value for `orderBy` argument: `' . $orderBy . '`');
}
$chunks = StringHelper::split($orderBy);
foreach ($chunks as $chunk) {
if (!preg_match('/^\w+(\.\w+)?( (asc|desc))?$/i', $chunk)) {
foreach (StringHelper::split($orderBy) as $chunk) {
// Special case for `RAND()`
if (strtolower($chunk) === 'rand()') {
continue;
}
if (
StringHelper::containsAny($orderBy, ['(', ')']) ||
!preg_match('/^\w+(\.\w+)?( (asc|desc))?$/i', $chunk)
) {
throw new GqlException('Illegal value for `orderBy` argument: `' . $orderBy . '`');
}
}
Expand Down

0 comments on commit f164ad2

Please sign in to comment.