Skip to content

Commit

Permalink
Merge pull request #163 from Slamdunk/backport_GHSA-jq4p-mq33-w375
Browse files Browse the repository at this point in the history
Backport GHSA-jq4p-mq33-w375 to v2
  • Loading branch information
Slamdunk authored Feb 1, 2022
2 parents 2a18e67 + 8496215 commit af231c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
"laminas/laminas-view": "^2.11.4, required for using the laminas-form view helpers"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"laminas": {
Expand Down
8 changes: 8 additions & 0 deletions src/View/Helper/FormElementErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use function array_merge;
use function array_walk_recursive;
use function count;
use function get_class;
use function gettype;
use function implode;
Expand Down Expand Up @@ -96,6 +97,13 @@ public function render(ElementInterface $element, array $attributes = [])
$attributes = ' ' . $attributes;
}

$count = count($messages);
$escaper = $this->getEscapeHtmlHelper();
for ($i = 0; $i < $count; $i += 1) {
$messages[$i] = $escaper($messages[$i]);
}


// Generate markup
$markup = sprintf($this->getMessageOpenFormat(), $attributes);
$markup .= implode($this->getMessageSeparatorString(), $messages);
Expand Down
18 changes: 18 additions & 0 deletions test/View/Helper/FormElementErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,22 @@ public function testCallingTheHelperToRenderInvokeCanReturnObject()
$helper = $this->helper;
$this->assertEquals($helper(), $helper);
}

public function testHtmlEscapingOfMessages(): void
{
$messages = [
[
'<span>First validator message</span>',
'<span>Second validator first message</span>',
'<span>Second validator second message</span>',
],
];
$element = new Element('foo');
$element->setMessages($messages);

$markup = $this->helper->render($element);

$this->assertStringNotContainsString('<span>', $markup);
$this->assertStringNotContainsString('</span>', $markup);
}
}

0 comments on commit af231c2

Please sign in to comment.