Skip to content
Open
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
8 changes: 7 additions & 1 deletion ProcessMaker/Models/ProcessRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@
* @param bool $formatted
* @return string
*/
public function evaluateCaseTitle(string $mustacheTitle, array $data, bool $formatted = false): string

Check failure on line 1067 in ProcessMaker/Models/ProcessRequest.php

View check run for this annotation

Decisions SonarQube / SonarQube Code Analysis

Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://builds.decisions.com:9000/project/issues?id=ProcessMaker_processmaker_AYkzkfKexYvY_isvKt07&pullRequest=9172&issues=eb95882d-4a13-4888-b849-dac492c465d9&open=eb95882d-4a13-4888-b849-dac492c465d9
{
if ($formatted) {
$mustache = new MustacheExpressionEvaluator([
Expand Down Expand Up @@ -1098,7 +1098,13 @@
$len += mb_strlen($part);
}
} else {
$mustache = new MustacheExpressionEvaluator();
$mustache = new MustacheExpressionEvaluator([
'escape' => function ($value) {
return is_scalar($value) || $value === null
? (string) $value
: '';
},
]);
$title = $mustache->render($mustacheTitle, $data);
// multi-byte 200 characters limit
$title = mb_substr($title, 0, 200);
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/ProcessMaker/CaseTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public function testEvaluateCaseTitleWithoutFormatting()
$this->assertEquals('Hello, World!', $title);
}

public function testEvaluateCaseTitleWithoutFormattingPreservesAmpersand()
{
$processRequest = new ProcessRequest();
$title = $processRequest->evaluateCaseTitle(
'Research {{department}}',
['department' => 'Research & Development'],
false
);

$this->assertSame('Research Research & Development', $title);
}

public function testEvaluateCaseTitleWithFormatting()
{
$processRequest = new ProcessRequest();
Expand All @@ -24,6 +36,18 @@ public function testEvaluateCaseTitleWithFormatting()
$this->assertEquals('Hello, <b>World</b>!', $title);
}

public function testEvaluateCaseTitleWithFormattingEscapesAmpersandForHtml()
{
$processRequest = new ProcessRequest();
$title = $processRequest->evaluateCaseTitle(
'Research {{department}}',
['department' => 'Research & Development'],
true
);

$this->assertSame('Research <b>Research &amp; Development</b>', $title);
}

public function testEvaluateCaseTitleWithCharacterLimit()
{
$processRequest = new ProcessRequest();
Expand Down
Loading