Skip to content

Commit a6835e4

Browse files
committed
Bugfix: Fix the issue with filtering.
1 parent a2e84ab commit a6835e4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

classes/wunderbyte_table.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,14 @@ public function apply_filter(string $filter, string &$searchtext = '') {
16751675
}
16761676
}
16771677

1678+
// Create a list of allowed keys that can be used for filtering.
1679+
$availablefilters = json_decode($this->filterjson);
1680+
if (!empty($availablefilters->categories)) {
1681+
$allowedfilters = array_map(fn($item) => $item->columnname, $availablefilters->categories);
1682+
} else {
1683+
$allowedfilters = [];
1684+
}
1685+
16781686
foreach ($categoryvalue as $key => $value) {
16791687
$filter .= ($categorycounter == 1) ? "" : " AND ";
16801688
$valuecounter = 1;
@@ -1684,16 +1692,16 @@ public function apply_filter(string $filter, string &$searchtext = '') {
16841692
$filter .= ($valuecounter == 1) ? "" : " AND ";
16851693

16861694
// In order to make sure we are dealing with real column names and no sql injection...
1687-
if (!array_key_exists($categorykey, $this->columns)) {
1688-
continue; // Or throw moodle_exception.
1695+
if (!in_array($categorykey, $allowedfilters)) {
1696+
continue;
16891697
}
16901698

16911699
// We check against allowed operators.
16921700
$allowedops = ['=', '<', '<=', '>', '>=', '<>', 'like', 'not like',
16931701
'in', 'not in', 'between', 'not between', 'is', 'is not', 'rlike', 'not rlike',
16941702
'regexp', 'not regexp', 'ilike', 'not ilike'];
16951703
if (!in_array($operator, $allowedops, true)) {
1696-
continue; // Or throw moodle_exception.
1704+
continue;
16971705
}
16981706

16991707
$paramkey = $this->set_params((string)$timestamp, false);

0 commit comments

Comments
 (0)