-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce mandatory tag attributes (#74)
* [FEATURE] Introduce mandatory tag attributes (Related: #71) * [TASK] Add iframe example scenario (Related: #70) * [TASK] Add tests for Attr flag assignment * [TASK] Add example for Attr::MANDATORY to README.md * [TASK] Resolve todos in ScenarioTest
- Loading branch information
Showing
6 changed files
with
199 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under the terms | ||
* of the MIT License (MIT). For the full copyright and license information, | ||
* please read the LICENSE file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\HtmlSanitizer\Behavior; | ||
|
||
use LogicException; | ||
|
||
class MultiTokenAttrValue implements AttrValueInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $delimiter; | ||
|
||
/** | ||
* @var list<string> | ||
*/ | ||
protected $tokens; | ||
|
||
public function __construct(string $delimiter, string ...$tokens) | ||
{ | ||
if ($delimiter === '') { | ||
throw new LogicException('Delimiter cannot be empty', 1642111976); | ||
} | ||
$tokens = array_filter($tokens, [$this, 'keepNonEmpty']); | ||
if ($tokens === []) { | ||
throw new LogicException('Tokens cannot be empty or only empty strings', 1642111637); | ||
} | ||
$this->delimiter = $delimiter; | ||
$this->tokens = $tokens; | ||
} | ||
|
||
public function matches(string $value): bool | ||
{ | ||
$tokens = explode($this->delimiter, $value); | ||
$tokens = array_filter($tokens, [$this, 'keepNonEmpty']); | ||
// in case there is no token, the result implicit is `true` | ||
// @todo has to be changed, in case mandatory tokes would be implemented | ||
if (empty($tokens)) { | ||
return true; | ||
} | ||
return array_diff($tokens, $this->tokens) === []; | ||
} | ||
|
||
protected function keepNonEmpty(string $item): bool | ||
{ | ||
return $item !== ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters