Skip to content

Commit

Permalink
Trim & Cut check string type (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcansado authored and rick-nu committed Aug 19, 2019
1 parent 49ba23a commit 7217f93
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/FilterRule/Cut.php
Expand Up @@ -45,6 +45,10 @@ public function __construct($start, $length = null)
*/
public function filter($value)
{
if (!is_string($value)) {
return $value;
}

if ($this->encodingFormat !== null) {
return mb_substr($value, $this->start, $this->length, $this->encodingFormat);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FilterRule/Trim.php
Expand Up @@ -40,7 +40,7 @@ public function __construct($characters = null)
*/
public function filter($value)
{
if ($value === null) {
if (!is_string($value)) {
return $value;
}

Expand Down
1 change: 1 addition & 0 deletions tests/FilterRule/CutTest.php
Expand Up @@ -51,6 +51,7 @@ public function getCutResults()
['text is kindaaaaaaaa longggggggg', 'gg', -2, null, null],
['Ce garçon est tombé par terre', 'Ce garçon est tombé', 0, 19, 'utf-8'],
['Τάχιστη αλώπηξ βαφής ψημένη γη', 'ψημένη', -9, 6, 'utf-8'],
[[], [], 0, 12, null]
];
}
}
1 change: 1 addition & 0 deletions tests/FilterRule/TrimTest.php
Expand Up @@ -55,6 +55,7 @@ public function getTrimResults()
[' !~! ', '!~!', null],
[' tabtab ', ' tabtab ', "\t"],
[null, null, null],
[[], [], null]
];
}
}

0 comments on commit 7217f93

Please sign in to comment.