Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6261-string-trim-all…
Browse files Browse the repository at this point in the history
…ows-0-in-charlist'

Close zendframework/zendframework#6261
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/StringTrim.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public function __construct($charlistOrOptions = null)
*/
public function setCharList($charList)
{
if (empty($charList)) {
if (! strlen($charList)) {
$charList = null;
}

$this->options['charlist'] = $charList;

return $this;
}

Expand Down
17 changes: 16 additions & 1 deletion test/StringTrimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use stdClass;

/**
* @group Zend_Filter
* @covers \Zend\Filter\StringTrim
*/
class StringTrimTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -157,4 +157,19 @@ public function testShouldNotFilterNonStringValues($value)
$filtered = $this->_filter->filter($value);
$this->assertSame($value, $filtered);
}

/**
* Ensures expected behavior with '0' as character list
*
* @group 6261
*/
public function testEmptyCharList()
{
$filter = $this->_filter;
$filter->setCharList('0');
$this->assertEquals('a0b', $filter('00a0b00'));

$filter->setCharList('');
$this->assertEquals('str', $filter(' str '));
}
}

0 comments on commit a2b31ea

Please sign in to comment.