Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions library/Zend/Filter/BaseName.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class BaseName extends AbstractFilter
*/
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))
));
}

return basename((string) $value);
}
}
8 changes: 8 additions & 0 deletions library/Zend/Filter/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class Digits extends AbstractFilter
*/
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 (!StringUtils::hasPcreUnicodeSupport()) {
// POSIX named classes are not supported, use alternative 0-9 match
$pattern = '/[^0-9]/';
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Filter/HtmlEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ public function setDoubleQuote($doubleQuote)
*/
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))
));
}

$filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
if (strlen((string) $value) && !strlen($filtered)) {
if (!function_exists('iconv')) {
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Filter/Int.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class Int extends AbstractFilter
*/
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))
));
}

return (int) ((string) $value);
}
}
8 changes: 8 additions & 0 deletions library/Zend/Filter/RealPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public function getExists()
*/
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))
));
}

$path = (string) $value;
if ($this->options['exists']) {
return realpath($path);
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Filter/StringToLower.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function __construct($encodingOrOptions = null)
*/
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 ($this->options['encoding'] !== null) {
return mb_strtolower((string) $value, $this->options['encoding']);
}
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Filter/StringToUpper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function __construct($encodingOrOptions = null)
*/
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 ($this->options['encoding'] !== null) {
return mb_strtoupper((string) $value, $this->options['encoding']);
}
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Filter/StripTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public function setAttributesAllowed($attributesAllowed)
*/
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))
));
}

$value = (string) $value;

// Strip HTML comments first
Expand Down
19 changes: 19 additions & 0 deletions tests/ZendTest/Filter/BaseNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,23 @@ public function testBasic()
$this->assertEquals($output, $filter($input));
}
}

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

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
19 changes: 19 additions & 0 deletions tests/ZendTest/Filter/DigitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,23 @@ public function testBasic()
);
}
}

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

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
18 changes: 18 additions & 0 deletions tests/ZendTest/Filter/HtmlEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ public function testRaisesExceptionIfEncodingMismatchDetectedAndFinalStringIsEmp
}
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$input = array('<', '>');

try {
$this->_filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}

/**
* Null error handler; used when wanting to ignore specific error types
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/ZendTest/Filter/IntTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,23 @@ public function testBasic()
$this->assertEquals($output, $filter($input));
}
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$filter = new IntFilter();
$input = array('123 test', '456 test');

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
22 changes: 22 additions & 0 deletions tests/ZendTest/Filter/RealPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,26 @@ public function testNonExistantPath()
. DIRECTORY_SEPARATOR . '_files';
$this->assertEquals($path, $filter($path3));
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$filter = $this->_filter;
$input = array(
$this->_filesPath . DIRECTORY_SEPARATOR . 'file.1',
$this->_filesPath . DIRECTORY_SEPARATOR . 'file.2'
);

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
18 changes: 18 additions & 0 deletions tests/ZendTest/Filter/StringToLowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,22 @@ public function testDetectMbInternalEncoding()

$this->assertEquals(mb_internal_encoding(), $this->_filter->getEncoding());
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$input = array('ABC', 'DEF');

try {
$this->_filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
18 changes: 18 additions & 0 deletions tests/ZendTest/Filter/StringToUpperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,22 @@ public function testDetectMbInternalEncoding()

$this->assertEquals(mb_internal_encoding(), $this->_filter->getEncoding());
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$input = array('abc', 'def');

try {
$this->_filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}
18 changes: 18 additions & 0 deletions tests/ZendTest/Filter/StripTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,22 @@ public function testFilterCanAllowHyphenatedAttributeNames()

$this->assertEquals($expected, $this->_filter->filter($input));
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
{
$input = array('<li data-name="Test User" data-id="11223"></li>', '<li data-name="Test User 2" data-id="456789"></li>');

try {
$this->_filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}

$this->fail('An expected InvalidArgumentException has not been raised.');
}
}