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

Commit

Permalink
Merge pull request #4761 in develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Jul 19, 2013
2 parents 1029b54 + 3148121 commit 4752541
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 124 deletions.
27 changes: 19 additions & 8 deletions library/Zend/Filter/BaseName.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ class BaseName extends AbstractFilter
/**
* Defined by Zend\Filter\FilterInterface
*
* Returns basename($value)
* Returns basename($value).
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

return basename((string) $value);
Expand Down
25 changes: 18 additions & 7 deletions library/Zend/Filter/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ class Digits extends AbstractFilter
*
* Returns the string $value, removing all but digit characters
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if (!StringUtils::hasPcreUnicodeSupport()) {
Expand Down
27 changes: 19 additions & 8 deletions library/Zend/Filter/HtmlEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,29 @@ public function setDoubleQuote($doubleQuote)
* Returns the string $value, converting characters to their corresponding HTML entity
* equivalents where they exist
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @throws Exception\DomainException
* @return string
* @return string|mixed
* @throws Exception\DomainException on encoding mismatches
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
Expand Down
25 changes: 18 additions & 7 deletions library/Zend/Filter/Int.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ class Int extends AbstractFilter
*
* Returns (int) $value
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return int
* @return int|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

return (int) ((string) $value);
Expand Down
25 changes: 18 additions & 7 deletions library/Zend/Filter/RealPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,28 @@ public function getExists()
*
* Returns realpath($value)
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$path = (string) $value;
Expand Down
25 changes: 18 additions & 7 deletions library/Zend/Filter/StringToLower.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,28 @@ public function __construct($encodingOrOptions = null)
*
* Returns the string $value, converting characters to lowercase as necessary
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if ($this->options['encoding'] !== null) {
Expand Down
27 changes: 19 additions & 8 deletions library/Zend/Filter/StringToUpper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,30 @@ public function __construct($encodingOrOptions = null)
/**
* Defined by Zend\Filter\FilterInterface
*
* Returns the string $value, converting characters to lowercase as necessary
* Returns the string $value, converting characters to uppercase as necessary
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if ($this->options['encoding'] !== null) {
Expand Down
26 changes: 18 additions & 8 deletions library/Zend/Filter/StripTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,29 @@ public function setAttributesAllowed($attributesAllowed)
/**
* Defined by Zend\Filter\FilterInterface
*
* @todo improve docblock descriptions
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @todo improve docblock descriptions
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)){
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$value = (string) $value;
Expand Down
27 changes: 19 additions & 8 deletions tests/ZendTest/Filter/BaseNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\Filter;

use Zend\Filter\BaseName as BaseNameFilter;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -38,21 +39,31 @@ public function testBasic()
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
* Ensures that a warning is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
public function testWarningIsRaisedIfArrayUsed()
{
$filter = new BaseNameFilter();
$input = array('/path/to/filename', '/path/to/filename.ext');

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}
ErrorHandler::start(E_USER_WARNING);
$filtered = $filter->filter($input);
$err = ErrorHandler::stop();

$this->assertEquals($input, $filtered);
$this->assertInstanceOf('ErrorException', $err);
$this->assertContains('cannot filter', $err->getMessage());
}

$this->fail('An expected InvalidArgumentException has not been raised.');
/**
* @return void
*/
public function testReturnsNullIfNullIsUsed()
{
$filter = new BaseNameFilter();
$filtered = $filter->filter(null);
$this->assertNull($filtered);
}
}
27 changes: 19 additions & 8 deletions tests/ZendTest/Filter/DigitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\Filter;

use Zend\Filter\Digits as DigitsFilter;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -87,21 +88,31 @@ public function testBasic()
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
* Ensures that an error is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
public function testWarningIsRaisedIfArrayUsed()
{
$filter = new DigitsFilter();
$input = array('abc123', 'abc 123');

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}
ErrorHandler::start(E_USER_WARNING);
$filtered = $filter->filter($input);
$err = ErrorHandler::stop();

$this->assertEquals($input, $filtered);
$this->assertInstanceOf('ErrorException', $err);
$this->assertContains('cannot filter', $err->getMessage());
}

$this->fail('An expected InvalidArgumentException has not been raised.');
/**
* @return void
*/
public function testReturnsNullIfNullIsUsed()
{
$filter = new DigitsFilter();
$filtered = $filter->filter(null);
$this->assertNull($filtered);
}
}

0 comments on commit 4752541

Please sign in to comment.