Commit df7378c4 authored by Frank Nägler's avatar Frank Nägler Committed by Wouter Wolters
Browse files

[TASK] Add validation for name option in FontAwesomeProvider

Resolves: #69384
Releases: master
Change-Id: I87703486b5233dd91eb7a40dd93633af114ea5ff
Reviewed-on: http://review.typo3.org/42903

Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
parent 6aab3bc7
......@@ -34,9 +34,16 @@ class FontawesomeIconProvider implements IconProviderInterface {
* @param Icon $icon
* @param array $options
*
* @throws \InvalidArgumentException
* @return string
*/
protected function generateMarkup(Icon $icon, array $options) {
if (empty($options['name'])) {
throw new \InvalidArgumentException('The option "name" is required and must not be empty', 1440754978);
}
if (preg_match('/^[a-zA-Z0-9\\-]+$/', $options['name']) !== 1) {
throw new \InvalidArgumentException('The option "name" must only contain characters a-z, A-Z, 0-9 or -', 1440754979);
}
$additionalClasses = (!empty($options['additionalClasses'])) ? ' ' . $options['additionalClasses'] : '';
return '<span class="icon-unify"><i class="fa fa-' . htmlspecialchars($options['name']) . htmlspecialchars($additionalClasses) . '"></i></span>';
}
......
......@@ -125,7 +125,8 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
'actions-edit-copy-release' => array(
'provider' => FontawesomeIconProvider::class,
'options' => array(
'name' => 'copy text-danger',
'name' => 'copy',
'additionalClasses' => 'text-danger',
)
),
'actions-edit-cut' => array(
......@@ -137,7 +138,8 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
'actions-edit-cut-release' => array(
'provider' => FontawesomeIconProvider::class,
'options' => array(
'name' => 'scissors text-danger',
'name' => 'scissors',
'additionalClasses' => 'text-danger',
)
),
'actions-edit-download' => array(
......@@ -223,7 +225,8 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
'status-status-current' => array(
'provider' => FontawesomeIconProvider::class,
'options' => array(
'name' => 'caret-right text-danger',
'name' => 'caret-right',
'additionalClasses' => 'text-danger',
)
),
......
......@@ -149,6 +149,7 @@ class IconFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
/**
* @test
* @dataProvider differentSizesDataProvider
* @param string $size
*/
public function getIconByIdentifierAndSizeAndOverlayReturnsNotFoundIconWithCorrectMarkupIfUnregisteredIdentifierIsUsed($size) {
$this->assertContains('<span class="icon-overlay icon-overlay-read-only">',
......
......@@ -59,4 +59,29 @@ class FontawesomeIconProviderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
$this->subject->prepareIconMarkup($this->icon, array('name' => 'times', 'additionalClasses' => 'foo'));
$this->assertEquals('<span class="icon-unify"><i class="fa fa-times foo"></i></span>', $this->icon->getMarkup());
}
/**
* DataProvider for icon names
*
* @return array
*/
public function wrongNamesDataProvider() {
return [
'name with spaces' => ['name with spaces'],
'name with spaces and umlauts' => ['name with spaces äöü'],
'name umlauts' => ['häuser'],
'name with underscore' => ['name_with_underscore'],
'name is empty' => [''],
];
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider wrongNamesDataProvider
* @param string $name
* @test
*/
public function prepareIconMarkupWithInvalidNameThrowsException($name) {
$this->subject->prepareIconMarkup($this->icon, array('name' => $name));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment