Skip to content

Commit 870e1ee

Browse files
Allow test names to contain "<" or ">" characters (Kitware#2972)
We recently received a bug report where test names were not being parsed correctly. https://open.cdash.org/viewTest.php?onlyfailed&buildid=10510619 The issue is that testing_handler's `text()` method gets called multiple times for the test name's character data when it includes escaped XML characters. The solution is to append (rather than replace) the value of `$testName` when this method gets called multiple times.
1 parent e30c606 commit 870e1ee

12 files changed

Lines changed: 145 additions & 20 deletions

File tree

app/Http/Controllers/TestController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ public function apiTestSummary(): JsonResponse|StreamedResponse
174174
}
175175
$this->setProjectById(intval($_GET['project'] ?? -1));
176176

177-
$testName = htmlspecialchars($_GET['name'] ?? '');
178-
if ($testName === '') {
177+
$testName = $_GET['name'] ?? '';
178+
if ($testName === '' || !is_string($testName)) {
179179
abort(400, 'No test name specified.');
180180
}
181181

app/Utils/TestCreator.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TestCreator
4343
public $testCommand;
4444
public $testDetails;
4545
public $testOutput;
46-
private $testName;
46+
public $testName;
4747
public $testPath;
4848
public $testStatus;
4949

@@ -135,19 +135,14 @@ public function computeCrc32(): int
135135
return crc32($crc32_input);
136136
}
137137

138-
/**
139-
* Set test name, truncated to 255 characters.
140-
*/
141-
public function setTestName(string $testName): void
142-
{
143-
$this->testName = substr($testName, 0, 255);
144-
}
145-
146138
/**
147139
* Record this test in the database.
148140
**/
149141
public function create(Build $build): void
150142
{
143+
// Truncate testName to 255 characters.
144+
$this->testName = substr($this->testName, 0, 255);
145+
151146
$crc32 = $this->computeCrc32();
152147

153148
// TODO: Convert this to Eloquent

app/cdash/include/filterdataFunctions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ function parse_filter_from_request($field_var, $compare_var, $value_var,
983983
$fieldinfo = explode('/', $fieldinfo, 2);
984984
$field = $fieldinfo[0];
985985
$compare = htmlspecialchars(pdo_real_escape_string($_REQUEST[$compare_var]));
986-
$value = htmlspecialchars(pdo_real_escape_string($_REQUEST[$value_var]));
986+
$value = pdo_real_escape_string($_REQUEST[$value_var]);
987987

988988
// The following filter types are considered 'date clauses' so that the
989989
// default date clause of "builds from today only" is not used...

app/cdash/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ add_feature_test(/Feature/GraphQL/BuildCommandTypeTest)
218218
add_feature_test(/Feature/GraphQL/BuildCommandOutputTypeTest)
219219

220220
add_feature_test(/Feature/Submission/Instrumentation/BuildInstrumentationTest)
221+
add_feature_test(/Feature/Submission/Tests/TestXMLTest)
221222

222223
add_feature_test(/Feature/RouteAccessTest)
223224

app/cdash/tests/test_buildproperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testUploadBuildProperties()
6363
$testcreator = new TestCreator();
6464
$testcreator->projectid = $this->Project->Id;
6565
$testcreator->testDetails = '';
66-
$testcreator->setTestName('BuildPropUnitTest');
66+
$testcreator->testName = 'BuildPropUnitTest';
6767
$testcreator->testPath = '/tmp';
6868
$testcreator->testCommand = 'echo foo';
6969
$testcreator->testOutput = 'foo';

app/cdash/tests/test_removebuilds.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testBuildRemovalWorksAsExpected(): void
262262
$test_creator->projectid = 1;
263263
$test_creator->alreadyCompressed = false;
264264
$test_creator->testDetails = 'Completed';
265-
$test_creator->setTestName('removal test');
265+
$test_creator->testName = 'removal test';
266266
$test_creator->testPath = '/path/to/removal/test';
267267
$test_creator->testCommand = 'php test_removebuilds.php';
268268
$test_creator->testOutput = 'build removed successfully';
@@ -291,7 +291,7 @@ public function testBuildRemovalWorksAsExpected(): void
291291
$test_creator2->projectid = 1;
292292
$test_creator2->alreadyCompressed = false;
293293
$test_creator2->testDetails = 'Completed';
294-
$test_creator2->setTestName('shared test');
294+
$test_creator2->testName = 'shared test';
295295
$test_creator2->testPath = '/path/to/shared/test';
296296
$test_creator2->testCommand = 'php test_sharedbuilds.php';
297297
$test_creator2->testOutput = 'build shared successfully';

app/cdash/xml_handlers/BazelJSON_handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function Parse($filename)
172172
$testCreator->projectid = $this->GetProject()->Id;
173173
$testCreator->testCommand = $this->CommandLine;
174174
$testCreator->testDetails = $testdata->details;
175-
$testCreator->setTestName($testdata->name);
175+
$testCreator->testName = $testdata->name;
176176
$testCreator->testStatus = $testdata->status;
177177

178178
if (array_key_exists($testdata->name, $this->TestsOutput)) {

app/cdash/xml_handlers/testing_handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ public function text($parser, $data)
283283
} elseif ($parent == 'TEST') {
284284
switch ($element) {
285285
case 'NAME':
286-
$this->TestCreator->setTestName($data);
286+
$this->TestCreator->testName .= $data;
287287
break;
288288
case 'PATH':
289-
$this->TestCreator->testPath = $data;
289+
$this->TestCreator->testPath .= $data;
290290
break;
291291
case 'FULLCOMMANDLINE':
292292
$this->TestCreator->testCommand .= $data;

app/cdash/xml_handlers/testing_j_unit_handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function startElement($parser, $name, $attributes): void
163163
}
164164
}
165165

166-
$this->TestCreator->setTestName($attributes['NAME']);
166+
$this->TestCreator->testName = $attributes['NAME'];
167167
$this->TestCreator->testPath = $attributes['CLASSNAME'];
168168
} elseif ($name == 'TESTSUITE') {
169169
// If the XML file doesn't have a <Site> tag then we use the information

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ parameters:
27152715
-
27162716
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#'
27172717
identifier: argument.type
2718-
count: 3
2718+
count: 2
27192719
path: app/Http/Controllers/TestController.php
27202720

27212721
-

0 commit comments

Comments
 (0)