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

Commit

Permalink
Merge pull request zendframework/zendframework#2210 from weierophinne…
Browse files Browse the repository at this point in the history
…y/hotfix/remove-suppression-operator

Get rid of error suppression
  • Loading branch information
Maks3w committed Aug 21, 2012
2 parents 5bd9f85 + ca0f92d commit a7848de
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/File/FilesSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator\Exception;

/**
Expand Down Expand Up @@ -111,7 +112,9 @@ public function isValid($value, $file = null)
}

// limited to 2GB files
$size += @filesize($files);
ErrorHandler::start();
$size += filesize($files);
ErrorHandler::stop();
$this->size = $size;
if (($max !== null) && ($max < $size)) {
if ($this->getByteString()) {
Expand Down
5 changes: 4 additions & 1 deletion src/File/ImageSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Validator\File;

use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;

Expand Down Expand Up @@ -336,7 +337,9 @@ public function isValid($value, $file = null)
return $this->throwError($file, self::NOT_READABLE);
}

$size = @getimagesize($value);
ErrorHandler::start();
$size = getimagesize($value);
ErrorHandler::stop();
$this->setValue($file);

if (empty($size) or ($size[0] === 0) or ($size[1] === 0)) {
Expand Down
30 changes: 23 additions & 7 deletions src/File/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;

Expand Down Expand Up @@ -145,7 +146,17 @@ public function getMagicFile()
$magic = getenv('magic');
if (!empty($magic)) {
$this->setMagicFile($magic);
} elseif (!(@ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1)) {
if ($this->options['magicFile'] === null) {
$this->options['magicFile'] = false;
}
return $this->options['magicFile'];
}

ErrorHandler::start();
$safeMode = ini_get('safe_mode');
ErrorHandler::stop();

if (!($safeMode == 'On' || $safeMode === 1)) {
foreach ($this->magicFiles as $file) {
// suppressing errors which are thrown due to openbase_dir restrictions
try {
Expand Down Expand Up @@ -195,16 +206,17 @@ public function setMagicFile($file)
));
} else {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
$this->finfo = @finfo_open($const, $file);
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
$this->finfo = null;
throw new Exception\InvalidMagicMimeFileException(sprintf(
'The given magicfile ("%s") could not be used by ext/finfo',
$file
));
} else {
$this->options['magicFile'] = $file;
), 0, $error);
}
$this->options['magicFile'] = $file;
}

return $this;
Expand Down Expand Up @@ -355,11 +367,15 @@ public function isValid($value, $file = null)
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
$this->finfo = @finfo_open($const, $mimefile);
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $mimefile);
ErrorHandler::stop();
}

if (empty($this->finfo)) {
$this->finfo = @finfo_open($const);
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const);
ErrorHandler::stop();
}

$this->type = null;
Expand Down
5 changes: 4 additions & 1 deletion src/File/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Validator\File;

use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;

Expand Down Expand Up @@ -247,7 +248,9 @@ public function isValid($value, $file = null)
}

// limited to 4GB files
$size = sprintf("%u", @filesize($value));
ErrorHandler::start();
$size = sprintf("%u", filesize($value));
ErrorHandler::stop();
$this->size = $size;

// Check to see if it's smaller than min size
Expand Down
10 changes: 8 additions & 2 deletions src/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Zend\Validator;

use Zend\Stdlib\ErrorHandler;

/**
* Please note there are two standalone test scripts for testing IDN characters due to problems
* with file encoding.
Expand Down Expand Up @@ -545,7 +547,9 @@ public function isValid($value)
// Check each domain part
$checked = false;
foreach ($regexChars as $regexKey => $regexChar) {
$status = @preg_match($regexChar, $domainPart);
ErrorHandler::start();
$status = preg_match($regexChar, $domainPart);
ErrorHandler::stop();
if ($status > 0) {
$length = 63;
if (array_key_exists(strtoupper($this->tld), $this->idnLength)
Expand Down Expand Up @@ -599,8 +603,10 @@ public function isValid($value)
}

// Check input against local network name schema; last chance to pass validation
ErrorHandler::start();
$regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}[\x2e]{0,1}){1,254}$/';
$status = @preg_match($regexLocal, $value);
$status = preg_match($regexLocal, $value);
ErrorHandler::stop();

// If the input passes as a local network name, and local network names are allowed, then the
// hostname passes validation
Expand Down
11 changes: 8 additions & 3 deletions src/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
Expand Down Expand Up @@ -96,11 +97,13 @@ public function getPattern()
*/
public function setPattern($pattern)
{
ErrorHandler::start();
$this->pattern = (string) $pattern;
$status = @preg_match($this->pattern, "Test");
$status = preg_match($this->pattern, "Test");
$error = ErrorHandler::stop();

if (false === $status) {
throw new Exception\InvalidArgumentException("Internal error parsing the pattern '{$this->pattern}'");
throw new Exception\InvalidArgumentException("Internal error parsing the pattern '{$this->pattern}'", 0, $error);
}

return $this;
Expand All @@ -121,7 +124,9 @@ public function isValid($value)

$this->setValue($value);

$status = @preg_match($this->pattern, $value);
ErrorHandler::start();
$status = preg_match($this->pattern, $value);
ErrorHandler::stop();
if (false === $status) {
$this->error(self::ERROROUS);
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/Sitemap/Lastmod.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Validator\Sitemap;

use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;

/**
Expand Down Expand Up @@ -62,7 +63,9 @@ public function isValid($value)
}

$this->setValue($value);
$result = @preg_match(self::LASTMOD_REGEX, $value);
ErrorHandler::start();
$result = preg_match(self::LASTMOD_REGEX, $value);
ErrorHandler::stop();
if ($result != 1) {
$this->error(self::NOT_VALID);
return false;
Expand Down

0 comments on commit a7848de

Please sign in to comment.