Skip to content

Commit

Permalink
Merge pull request #31 from Ingewikkeld/null-value-handling
Browse files Browse the repository at this point in the history
make StripHtml and Trim return a null value if a null value is passed to it
  • Loading branch information
Rick van der Staaij authored and Rick van der Staaij committed Jun 30, 2015
2 parents 57fe150 + 27f1bbc commit dc448b0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/FilterRule/StripHtml.php
Expand Up @@ -40,6 +40,10 @@ public function __construct($excludeTags = null)
*/
public function filter($value)
{
if ($value === null) {
return $value;
}

return strip_tags($value, $this->excludeTags);
}
}
4 changes: 4 additions & 0 deletions src/FilterRule/Trim.php
Expand Up @@ -40,6 +40,10 @@ public function __construct($characters = null)
*/
public function filter($value)
{
if ($value === null) {
return $value;
}

if ($this->characters === null) {
return trim($value);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/FilterRule/StripHtmlTest.php
Expand Up @@ -32,7 +32,7 @@ public function testStripHtmlFilterRule($value, $excludeTags, $filteredValue)
'test' => $value
]);

$this->assertEquals($filteredValue, $result['test']);
$this->assertSame($filteredValue, $result['test']);
}

/**
Expand All @@ -44,6 +44,7 @@ public function getStripHtmlResults()
['', '', ''],
['<p><strong>t</strong>ext</p>', null, 'text'],
['<p><strong>t</strong>ext</p>', '<p>', '<p>text</p>'],
[null, null, null],
];
}
}
3 changes: 2 additions & 1 deletion tests/FilterRule/TrimTest.php
Expand Up @@ -36,7 +36,7 @@ public function testTrimFilterRule($value, $filteredValue, $characters)
'test' => $value
]);

$this->assertEquals($filteredValue, $result['test']);
$this->assertSame($filteredValue, $result['test']);
}

/**
Expand All @@ -54,6 +54,7 @@ public function getTrimResults()
[' abc ', 'abc', null],
[' !~! ', '!~!', null],
[' tabtab ', ' tabtab ', "\t"],
[null, null, null],
];
}
}

0 comments on commit dc448b0

Please sign in to comment.