diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index d0e2aa2a..a79679bc 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -319,29 +319,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/StripTags.php b/src/StripTags.php
index fa7fb3be..2db7baf6 100644
--- a/src/StripTags.php
+++ b/src/StripTags.php
@@ -21,7 +21,7 @@
/**
* @psalm-type Options = array{
- * allowTags?: array>,
+ * allowTags?: list|array>,
* allowAttribs?: list
* }
* @implements FilterInterface
@@ -60,8 +60,6 @@ public function __construct(array $options = [])
* Defined by Laminas\Filter\FilterInterface
*
* If the value provided is non-scalar, the value will remain unfiltered
- *
- * @psalm-return ($value is scalar ? string : mixed)
*/
public function filter(mixed $value): mixed
{
@@ -117,6 +115,9 @@ public function __invoke(mixed $value): mixed
return $this->filter($value);
}
+ /**
+ * @param array> $tagsAllowed
+ */
private function setTagsAllowed(array $tagsAllowed): void
{
foreach ($tagsAllowed as $index => $element) {
@@ -126,22 +127,16 @@ private function setTagsAllowed(array $tagsAllowed): void
$tagName = strtolower($element);
// Store the tag as allowed with no attributes
$this->tagsAllowed[$tagName] = [];
- } elseif (is_string($index) && (is_array($element) || is_string($element))) {
+ } elseif (is_string($index) && is_array($element)) {
// Otherwise, if a tag was provided with attributes
// Canonicalize the tag name
$tagName = strtolower($index);
- // Canonicalize the attributes
- if (is_string($element)) {
- $element = [$element];
- }
// Store the tag as allowed with the provided attributes
$this->tagsAllowed[$tagName] = [];
foreach ($element as $attribute) {
- if (is_string($attribute)) {
- // Canonicalize the attribute name
- $attributeName = strtolower($attribute);
- $this->tagsAllowed[$tagName][$attributeName] = null;
- }
+ // Canonicalize the attribute name
+ $attributeName = strtolower($attribute);
+ $this->tagsAllowed[$tagName][$attributeName] = null;
}
}
}
@@ -154,11 +149,9 @@ private function setAttributesAllowed(array $attributesAllowed): void
{
// Store each attribute as allowed
foreach ($attributesAllowed as $attribute) {
- if (is_string($attribute)) {
- // Canonicalize the attribute name
- $attributeName = strtolower($attribute);
- $this->attributesAllowed[$attributeName] = null;
- }
+ // Canonicalize the attribute name
+ $attributeName = strtolower($attribute);
+ $this->attributesAllowed[$attributeName] = null;
}
}
diff --git a/test/StripTagsTest.php b/test/StripTagsTest.php
index 779e91f3..2cbb849f 100644
--- a/test/StripTagsTest.php
+++ b/test/StripTagsTest.php
@@ -123,7 +123,7 @@ public function testFilterTagAllowedAttribute(): void
public function testFilterTagAllowedAttributeAllowed(): void
{
$filter = new StripTagsFilter([
- 'allowTags' => ['img' => 'alt'],
+ 'allowTags' => ['img' => ['alt']],
]);
$input = '';
$expected = '';
@@ -138,7 +138,7 @@ public function testFilterTagAllowedAttributeAllowed(): void
public function testFilterTagAllowedAttributeAllowedGt(): void
{
$filter = new StripTagsFilter([
- 'allowTags' => ['img' => 'alt'],
+ 'allowTags' => ['img' => ['alt']],
]);
$input = '';
$expected = 'property" /';
@@ -151,7 +151,7 @@ public function testFilterTagAllowedAttributeAllowedGt(): void
public function testFilterTagAllowedAttributeAllowedGtEscaped(): void
{
$filter = new StripTagsFilter([
- 'allowTags' => ['img' => 'alt'],
+ 'allowTags' => ['img' => ['alt']],
]);
$input = '';
$expected = '';
@@ -242,7 +242,7 @@ public function testClosingAngleBracketInAllowedAttributeValue(): void
{
$filter = new StripTagsFilter([
'allowTags' => [
- 'a' => 'href',
+ 'a' => ['href'],
],
]);
$input = '';
@@ -259,7 +259,7 @@ public function testAllowedAttributeValueMayEndWithEquals(): void
{
$filter = new StripTagsFilter([
'allowTags' => [
- 'element' => 'attribute',
+ 'element' => ['attribute'],
],
]);
$input = 'contents';