Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/cdash/include/filterdataFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,28 @@ function get_sql_compare_and_value($compare, $value): array

// Parse a filter's field, compare, and value from the request and return an
// associative array representation of this filter.
// Returns an empty array if none of them were given, and aborts with a 400 if
// only some of them were.
// This function also sets the 'hasdateclause' field in $filterdata
// if necessary.
function parse_filter_from_request($field_var, $compare_var, $value_var,
&$filterdata): array
{
$required_params = [$field_var, $compare_var, $value_var];
$missing_params = [];
foreach ($required_params as $param) {
if (!array_key_exists($param, $_REQUEST)) {
return [];
$missing_params[] = $param;
}
}
if ($missing_params === $required_params) {
// The filter UIs count empty blocks of filters in filtercount, but send none of their parameters.
return [];
}
if ($missing_params !== []) {
// Ignoring an incomplete filter would widen the query instead, possibly to every test of the day.
abort(400, 'Incomplete filter: missing ' . implode(', ', $missing_params));
}

$fieldinfo = htmlspecialchars(pdo_real_escape_string($_REQUEST[$field_var]));
$fieldinfo = explode('/', $fieldinfo, 2);
Expand Down
38 changes: 38 additions & 0 deletions tests/Browser/Pages/QueryTestsPageFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,44 @@ public function testFiltersTests(string $field, string $compare, string $value,
});
}

public function testIgnoresFiltersWithoutParameters(): void
{
$build = $this->createBuild();
$build->tests()->create(['testname' => 'kept', 'status' => Test::PASSED]);
$build->tests()->create(['testname' => 'removed', 'status' => Test::PASSED]);

$this->browse(function (Browser $browser): void {
// The filters panel counts an empty block of filters, but doesn't send its parameters.
$browser->visit("/queryTests.php?project={$this->project->name}&date=2025-01-15"
. '&filtercount=2&showfilters=1&field1=testname&compare1=61&value1=kept');
$this->assertTestNames($browser, ['kept']);
});
}

/**
* @return array<string,array{string,string}>
*/
public static function incompleteFilters(): array
{
return [
'value only' => ['&value1=kept', 'field1, compare1'],
'no compare' => ['&field1=testname&value1=kept', 'compare1'],
'no value' => ['&field1=testname&compare1=61', 'value1'],
'in a block' => ['&field1=block&field1count=1&field1field1=testname&field1value1=kept', 'field1compare1'],
];
}

#[DataProvider('incompleteFilters')]
public function testRejectsIncompleteFilters(string $filter, string $missing): void
{
$this->browse(function (Browser $browser) use ($filter, $missing): void {
// Ignoring the incomplete filter would list every test of the day instead.
$browser->visit("/queryTests.php?project={$this->project->name}&date=2025-01-15&filtercount=1&showfilters=1{$filter}")
->waitForTextIn('@error-message', "Incomplete filter: missing {$missing}")
->assertNotPresent('@tests-table');
});
}

public function testFilteringByBuildStartTimeIncludesOtherDays(): void
{
foreach (['2025-01-13', '2025-01-15', '2025-01-17'] as $date) {
Expand Down
Loading