Skip to content

Commit

Permalink
Merge pull request #51 from maxmilash/trim-php8-fix
Browse files Browse the repository at this point in the history
fix Trim filter with null or other non-string value with strict_types=1
  • Loading branch information
rdohms authored Oct 11, 2021
2 parents be79368 + bcf753c commit ef4c214
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DMS/Filter/Filters/Trim.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use DMS\Filter\Rules\Rule;

use function is_string;
use function trim;

/**
Expand All @@ -19,6 +20,10 @@ class Trim extends BaseFilter
*/
public function apply(Rule $rule, $value)
{
if (! is_string($value)) {
return $value;
}

//trim() only operates in default mode
//if no second argument is passed, it
//cannot be passed as null
Expand Down
1 change: 1 addition & 0 deletions tests/DMS/Filter/Filters/TrimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function provideForRule(): array
[['charlist' => "\\"], "\my text", "my text"],
["\\", "\my text", "my text"],
["x", "xmy textx", "my text"],
[[], null, null],
];
}
}

0 comments on commit ef4c214

Please sign in to comment.