updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -133,9 +133,9 @@ abstract class AbstractValidator implements
foreach ($options as $name => $option) {
$fname = 'set' . ucfirst($name);
$fname2 = 'is' . ucfirst($name);
if (($name != 'setOptions') && method_exists($this, $name)) {
if (($name !== 'setOptions') && method_exists($this, $name)) {
$this->{$name}($option);
} elseif (($fname != 'setOptions') && method_exists($this, $fname)) {
} elseif (($fname !== 'setOptions') && method_exists($this, $fname)) {
$this->{$fname}($option);
} elseif (method_exists($this, $fname2)) {
$this->{$fname2}($option);

View File

@@ -279,7 +279,7 @@ class CreditCard extends AbstractValidator
$foundl = false;
foreach ($types as $type) {
foreach ($this->cardType[$type] as $prefix) {
if (substr($value, 0, strlen($prefix)) == $prefix) {
if (0 === strpos($value, $prefix)) {
$foundp = true;
if (in_array($length, $this->cardLength[$type])) {
$foundl = true;

View File

@@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2019 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@@ -56,6 +56,11 @@ class Date extends AbstractValidator
*/
protected $format = self::FORMAT_DEFAULT;
/**
* @var bool
*/
protected $strict = false;
/**
* Sets validator options
*
@@ -100,6 +105,17 @@ class Date extends AbstractValidator
return $this;
}
public function setStrict(bool $strict) : self
{
$this->strict = $strict;
return $this;
}
public function isStrict() : bool
{
return $this->strict;
}
/**
* Returns true if $value is a DateTime instance or can be converted into one.
*
@@ -110,11 +126,17 @@ class Date extends AbstractValidator
{
$this->setValue($value);
if (! $this->convertToDateTime($value)) {
$date = $this->convertToDateTime($value);
if (! $date) {
$this->error(self::INVALID_DATE);
return false;
}
if ($this->isStrict() && $date->format($this->getFormat()) !== $value) {
$this->error(self::FALSEFORMAT);
return false;
}
return true;
}

View File

@@ -166,10 +166,10 @@ class DateStep extends Date
if (strpos($this->format, 'Y-\WW') === 0
&& preg_match('/^([0-9]{4})\-W([0-9]{2})/', $value, $matches)
) {
$date = new DateTime;
$date = new DateTime();
$date->setISODate($matches[1], $matches[2]);
} else {
$date = DateTime::createFromFormat($this->format, $value, $this->timezone);
$date = DateTime::createFromFormat($this->format, $value, new DateTimeZone('UTC'));
}
// Invalid dates can show up as warnings (ie. "2007-02-99")

0
vendor/zendframework/zend-validator/src/Db/AbstractDb.php vendored Normal file → Executable file
View File

View File

@@ -206,6 +206,6 @@ class Explode extends AbstractValidator implements ValidatorPluginManagerAwareIn
}
}
return count($this->abstractOptions['messages']) == 0;
return ! $this->abstractOptions['messages'];
}
}

View File

@@ -9,13 +9,15 @@
namespace Zend\Validator\File;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the crc32 hash of given files
*/
class Crc32 extends Hash
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -85,32 +87,18 @@ class Crc32 extends Hash
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('crc32', $file);
$filehash = hash_file('crc32', $fileInfo['file']);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
return false;

View File

@@ -9,6 +9,7 @@
namespace Zend\Validator\File;
use Zend\Validator\File\FileInformationTrait;
use Zend\Validator\Exception;
/**
@@ -16,6 +17,8 @@ use Zend\Validator\Exception;
*/
class ExcludeExtension extends Extension
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -40,31 +43,21 @@ class ExcludeExtension extends Extension
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (! $this->getAllowNonExistentFile()
&& (empty($fileInfo['file']) || false === is_readable($fileInfo['file']))
) {
if (preg_match('/nofile\.mo$/', $fileInfo['file'])) {
}
$this->error(self::NOT_FOUND);
return false;
}
$extension = substr($filename, strrpos($filename, '.') + 1);
$this->setValue($fileInfo['filename']);
$extension = substr($fileInfo['filename'], strrpos($fileInfo['filename'], '.') + 1);
$extensions = $this->getExtension();
if ($this->getCase() && (! in_array($extension, $extensions))) {
@@ -72,6 +65,8 @@ class ExcludeExtension extends Extension
} elseif (! $this->getCase()) {
foreach ($extensions as $ext) {
if (strtolower($ext) == strtolower($extension)) {
if (preg_match('/nofile\.mo$/', $fileInfo['file'])) {
}
$this->error(self::FALSE_EXTENSION);
return false;
}

View File

@@ -10,13 +10,15 @@
namespace Zend\Validator\File;
use finfo;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the mime type of a file
*/
class ExcludeMimeType extends MimeType
{
use FileInformationTrait;
const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
@@ -41,29 +43,12 @@ class ExcludeMimeType extends MimeType
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
$filetype = $value['type'];
} else {
$file = $value;
$filename = basename($file);
$filetype = null;
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file, true);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_READABLE);
return false;
}
@@ -80,12 +65,12 @@ class ExcludeMimeType extends MimeType
$this->type = null;
if (! empty($this->finfo)) {
$this->type = finfo_file($this->finfo, $file);
$this->type = finfo_file($this->finfo, $fileInfo['file']);
}
}
if (empty($this->type) && $this->getHeaderCheck()) {
$this->type = $filetype;
$this->type = $fileInfo['filetype'];
}
if (empty($this->type)) {

View File

@@ -11,12 +11,15 @@ namespace Zend\Validator\File;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator which checks if the file already exists in the directory
*/
class Exists extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -144,31 +147,15 @@ class Exists extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = basename($file);
$this->setValue($value['name']);
} else {
$file = $value;
$filename = basename($file);
$this->setValue($filename);
}
$fileInfo = $this->getFileInfo($value, $file, false, true);
$this->setValue($fileInfo['filename']);
$check = false;
$directories = $this->getDirectory(true);
if (! isset($directories)) {
$check = true;
if (! file_exists($file)) {
if (! file_exists($fileInfo['file'])) {
$this->error(self::DOES_NOT_EXIST);
return false;
}
@@ -179,7 +166,7 @@ class Exists extends AbstractValidator
}
$check = true;
if (! file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
if (! file_exists($directory . DIRECTORY_SEPARATOR . $fileInfo['basename'])) {
$this->error(self::DOES_NOT_EXIST);
return false;
}

View File

@@ -12,6 +12,7 @@ namespace Zend\Validator\File;
use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
use Zend\Validator\File\FileInformationTrait;
use Zend\Validator\Exception;
/**
@@ -19,6 +20,8 @@ use Zend\Validator\Exception;
*/
class Extension extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -41,6 +44,7 @@ class Extension extends AbstractValidator
protected $options = [
'case' => false, // Validate case sensitive
'extension' => '', // List of extensions
'allowNonExistentFile' => false, // Allow validation even if file does not exist
];
/**
@@ -167,6 +171,28 @@ class Extension extends AbstractValidator
return $this;
}
/**
* Returns whether or not to allow validation of non-existent files.
*
* @return bool
*/
public function getAllowNonExistentFile()
{
return $this->options['allowNonExistentFile'];
}
/**
* Sets the flag indicating whether or not to allow validation of non-existent files.
*
* @param bool $flag Whether or not to allow validation of non-existent files.
* @return self Provides a fluent interface
*/
public function setAllowNonExistentFile($flag)
{
$this->options['allowNonExistentFile'] = (bool) $flag;
return $this;
}
/**
* Returns true if and only if the file extension of $value is included in the
* set extension list
@@ -177,31 +203,19 @@ class Extension extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (! $this->getAllowNonExistentFile()
&& (empty($fileInfo['file']) || false === is_readable($fileInfo['file']))
) {
$this->error(self::NOT_FOUND);
return false;
}
$extension = substr($filename, strrpos($filename, '.') + 1);
$this->setValue($fileInfo['filename']);
$extension = substr($fileInfo['filename'], strrpos($fileInfo['filename'], '.') + 1);
$extensions = $this->getExtension();
if ($this->getCase() && (in_array($extension, $extensions))) {

View File

@@ -0,0 +1,166 @@
<?php
/**
* @see https://github.com/zendframework/zend-validator for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-validator/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Validator\File;
use Psr\Http\Message\UploadedFileInterface;
use Zend\Validator\Exception;
trait FileInformationTrait
{
/**
* Returns array if the procedure is identified
*
* @param string|array|object $value Filename to check
* @param null|array $file File data (when using legacy Zend_File_Transfer API)
* @param bool $hasType Return with filetype (optional)
* @param bool $basename Return with basename - is calculated from location path (optional)
* @return array
*/
protected function getFileInfo(
$value,
array $file = null,
$hasType = false,
$hasBasename = false
) {
if (is_string($value) && is_array($file)) {
return $this->getLegacyFileInfo($file, $hasType, $hasBasename);
}
if (is_array($value)) {
return $this->getSapiFileInfo($value, $hasType, $hasBasename);
}
if ($value instanceof UploadedFileInterface) {
return $this->getPsr7FileInfo($value, $hasType, $hasBasename);
}
return $this->getFileBasedFileInfo($value, $hasType, $hasBasename);
}
/**
* Generate file information array with legacy Zend_File_Transfer API
*
* @param array $file File data
* @param bool $hasType Return with filetype
* @param bool $hasBasename Basename is calculated from location path
* @return array
*/
private function getLegacyFileInfo(
array $file,
$hasType = false,
$hasBasename = false
) {
$fileInfo = [];
$fileInfo['filename'] = $file['name'];
$fileInfo['file'] = $file['tmp_name'];
if ($hasBasename) {
$fileInfo['basename'] = basename($fileInfo['file']);
}
if ($hasType) {
$fileInfo['filetype'] = $file['type'];
}
return $fileInfo;
}
/**
* Generate file information array with SAPI
*
* @param array $file File data from SAPI
* @param bool $hasType Return with filetype
* @param bool $hasBasename Filename is calculated from location path
* @return array
*/
private function getSapiFileInfo(
array $file,
$hasType = false,
$hasBasename = false
) {
if (! isset($file['tmp_name']) || ! isset($file['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$fileInfo = [];
$fileInfo['file'] = $file['tmp_name'];
$fileInfo['filename'] = $file['name'];
if ($hasBasename) {
$fileInfo['basename'] = basename($fileInfo['file']);
}
if ($hasType) {
$fileInfo['filetype'] = $file['type'];
}
return $fileInfo;
}
/**
* Generate file information array with PSR-7 UploadedFileInterface
*
* @param UploadedFileInterface $file
* @param bool $hasType Return with filetype
* @param bool $hasBasename Filename is calculated from location path
* @return array
*/
private function getPsr7FileInfo(
UploadedFileInterface $file,
$hasType = false,
$hasBasename = false
) {
$fileInfo = [];
$fileInfo['file'] = $file->getStream()->getMetadata('uri');
$fileInfo['filename'] = $file->getClientFilename();
if ($hasBasename) {
$fileInfo['basename'] = basename($fileInfo['file']);
}
if ($hasType) {
$fileInfo['filetype'] = $file->getClientMediaType();
}
return $fileInfo;
}
/**
* Generate file information array with base method
*
* @param string $file File path
* @param bool $hasType Return with filetype
* @param bool $hasBasename Filename is calculated from location path
* @return array
*/
private function getFileBasedFileInfo(
$file,
$hasType = false,
$hasBasename = false
) {
$fileInfo = [];
$fileInfo['file'] = $file;
$fileInfo['filename'] = basename($fileInfo['file']);
if ($hasBasename) {
$fileInfo['basename'] = basename($fileInfo['file']);
}
if ($hasType) {
$fileInfo['filetype'] = null;
}
return $fileInfo;
}
}

View File

@@ -151,7 +151,7 @@ class FilesSize extends Size
}
}
if (count($this->getMessages()) > 0) {
if ($this->getMessages()) {
return false;
}

View File

@@ -11,12 +11,15 @@ namespace Zend\Validator\File;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the hash of given files
*/
class Hash extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -114,6 +117,12 @@ class Hash extends AbstractValidator
}
foreach ($options as $value) {
if (! is_string($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Hash must be a string, %s received',
is_object($value) ? get_class($value) : gettype($value)
));
}
$this->options['hash'][$value] = $algorithm;
}
@@ -129,43 +138,27 @@ class Hash extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
$algos = array_unique(array_values($this->getHash()));
$hashes = array_unique(array_keys($this->getHash()));
$algos = array_unique(array_values($this->getHash()));
foreach ($algos as $algorithm) {
$filehash = hash_file($algorithm, $file);
$filehash = hash_file($algorithm, $fileInfo['file']);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
return false;
}
foreach ($hashes as $hash) {
if ($filehash === $hash) {
return true;
}
if (isset($this->getHash()[$filehash]) && $this->getHash()[$filehash] === $algorithm) {
return true;
}
}

View File

@@ -12,12 +12,15 @@ namespace Zend\Validator\File;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the image size of an image file
*/
class ImageSize extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -332,32 +335,18 @@ class ImageSize extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_READABLE);
return false;
}
ErrorHandler::start();
$size = getimagesize($file);
$size = getimagesize($fileInfo['file']);
ErrorHandler::stop();
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
@@ -383,7 +372,7 @@ class ImageSize extends AbstractValidator
$this->error(self::HEIGHT_TOO_BIG);
}
if (count($this->getMessages()) > 0) {
if ($this->getMessages()) {
return false;
}

View File

@@ -74,6 +74,7 @@ class IsImage extends MimeType
'image/vnd.djvu',
'image/vnd.fpx',
'image/vnd.net-fpx',
'image/webp',
'image/x-cmu-raster',
'image/x-cmx',
'image/x-coreldraw',

View File

@@ -9,13 +9,15 @@
namespace Zend\Validator\File;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the md5 hash of given files
*/
class Md5 extends Hash
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -85,32 +87,18 @@ class Md5 extends Hash
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('md5', $file);
$filehash = hash_file('md5', $fileInfo['file']);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
return false;

View File

@@ -14,12 +14,15 @@ use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the mime type of a file
*/
class MimeType extends AbstractValidator
{
use FileInformationTrait;
/**#@+
* @const Error type constants
*/
@@ -341,29 +344,12 @@ class MimeType extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
$filetype = $value['type'];
} else {
$file = $value;
$filename = basename($file);
$filetype = null;
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file, true);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(static::NOT_READABLE);
return false;
}
@@ -384,13 +370,13 @@ class MimeType extends AbstractValidator
$this->type = null;
if (! empty($this->finfo)) {
$this->type = finfo_file($this->finfo, $file);
$this->type = finfo_file($this->finfo, $fileInfo['file']);
unset($this->finfo);
}
}
if (empty($this->type) && $this->getHeaderCheck()) {
$this->type = $filetype;
$this->type = $fileInfo['filetype'];
}
if (empty($this->type)) {

View File

@@ -10,12 +10,15 @@
namespace Zend\Validator\File;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator which checks if the destination file does not exist
*/
class NotExists extends Exists
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -37,31 +40,15 @@ class NotExists extends Exists
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = basename($file);
$this->setValue($value['name']);
} else {
$file = $value;
$filename = basename($file);
$this->setValue($filename);
}
$fileInfo = $this->getFileInfo($value, $file, false, true);
$this->setValue($fileInfo['filename']);
$check = false;
$directories = $this->getDirectory(true);
if (! isset($directories)) {
$check = true;
if (file_exists($file)) {
if (file_exists($fileInfo['file'])) {
$this->error(self::DOES_EXIST);
return false;
}
@@ -72,7 +59,7 @@ class NotExists extends Exists
}
$check = true;
if (file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
if (file_exists($directory . DIRECTORY_SEPARATOR . $fileInfo['basename'])) {
$this->error(self::DOES_EXIST);
return false;
}

View File

@@ -9,13 +9,15 @@
namespace Zend\Validator\File;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the sha1 hash of given files
*/
class Sha1 extends Hash
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -85,32 +87,18 @@ class Sha1 extends Hash
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('sha1', $file);
$filehash = hash_file('sha1', $fileInfo['file']);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
return false;

View File

@@ -12,12 +12,15 @@ namespace Zend\Validator\File;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for the maximum size of a file up to a max of 2GB
*/
class Size extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -234,33 +237,19 @@ class Size extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
// limited to 4GB files
ErrorHandler::start();
$size = sprintf("%u", filesize($file));
$size = sprintf("%u", filesize($fileInfo['file']));
ErrorHandler::stop();
$this->size = $size;
@@ -292,7 +281,7 @@ class Size extends AbstractValidator
}
}
if (count($this->getMessages()) > 0) {
if ($this->getMessages()) {
return false;
}

View File

@@ -10,6 +10,7 @@
namespace Zend\Validator\File;
use Countable;
use Psr\Http\Message\UploadedFileInterface;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
@@ -37,13 +38,14 @@ class Upload extends AbstractValidator
* @var array Error message templates
*/
protected $messageTemplates = [
self::INI_SIZE => "File '%value%' exceeds the defined ini size",
self::FORM_SIZE => "File '%value%' exceeds the defined form size",
self::INI_SIZE => "File '%value%' exceeds upload_max_filesize directive in php.ini",
self::FORM_SIZE => "File '%value%' exceeds the MAX_FILE_SIZE directive that was "
. 'specified in the HTML form',
self::PARTIAL => "File '%value%' was only partially uploaded",
self::NO_FILE => "File '%value%' was not uploaded",
self::NO_TMP_DIR => "No temporary directory was found for file '%value%'",
self::CANT_WRITE => "File '%value%' can't be written",
self::EXTENSION => "A PHP extension returned an error while uploading the file '%value%'",
self::NO_TMP_DIR => "Missing a temporary folder to store '%value%'",
self::CANT_WRITE => "Failed to write file '%value%' to disk",
self::EXTENSION => "A PHP extension stopped uploading the file '%value%'",
self::ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack",
self::FILE_NOT_FOUND => "File '%value%' was not found",
self::UNKNOWN => "Unknown error while uploading file '%value%'"
@@ -87,12 +89,16 @@ class Upload extends AbstractValidator
$return[$file] = $this->options['files'][$name];
}
if ($content['name'] === $file) {
if ($content instanceof UploadedFileInterface) {
if ($content->getClientFilename() === $file) {
$return[$name] = $this->options['files'][$name];
}
} elseif ($content['name'] === $file) {
$return[$name] = $this->options['files'][$name];
}
}
if (count($return) === 0) {
if (! $return) {
throw new Exception\InvalidArgumentException("The file '$file' was not found");
}
@@ -124,7 +130,9 @@ class Upload extends AbstractValidator
}
foreach ($this->options['files'] as $file => $content) {
if (! isset($content['error'])) {
if (! $content instanceof UploadedFileInterface
&& ! isset($content['error'])
) {
unset($this->options['files'][$file]);
}
}
@@ -148,6 +156,18 @@ class Upload extends AbstractValidator
$files = array_merge($files, $this->getFiles($value));
} else {
foreach ($this->getFiles() as $file => $content) {
if ($content instanceof UploadedFileInterface) {
if ($content->getClientFilename() === $value) {
$files = array_merge($files, $this->getFiles($file));
}
// PSR cannot search by tmp_name because it does not have
// a public interface to get it, only user defined name
// from form field.
continue;
}
if (isset($content['name']) && ($content['name'] === $value)) {
$files = array_merge($files, $this->getFiles($file));
}
@@ -164,8 +184,19 @@ class Upload extends AbstractValidator
foreach ($files as $file => $content) {
$this->value = $file;
switch ($content['error']) {
$error = $content instanceof UploadedFileInterface
? $content->getError()
: $content['error'];
switch ($error) {
case 0:
if ($content instanceof UploadedFileInterface) {
// done!
break;
}
// For standard SAPI environments, check that the upload
// was valid
if (! is_uploaded_file($content['tmp_name'])) {
$this->throwError($content, self::ATTACK);
}
@@ -205,7 +236,7 @@ class Upload extends AbstractValidator
}
}
if (count($this->getMessages()) > 0) {
if ($this->getMessages()) {
return false;
}
@@ -215,7 +246,7 @@ class Upload extends AbstractValidator
/**
* Throws an error of the given type
*
* @param string $file
* @param array|string|UploadedFileInterface $file
* @param string $errorType
* @return false
*/
@@ -228,6 +259,8 @@ class Upload extends AbstractValidator
}
} elseif (is_string($file)) {
$this->value = $file;
} elseif ($file instanceof UploadedFileInterface) {
$this->value = $file->getClientFilename();
}
}

View File

@@ -9,6 +9,7 @@
namespace Zend\Validator\File;
use Psr\Http\Message\UploadedFileInterface;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
@@ -35,22 +36,23 @@ class UploadFile extends AbstractValidator
* @var array Error message templates
*/
protected $messageTemplates = [
self::INI_SIZE => "File exceeds the defined ini size",
self::FORM_SIZE => "File exceeds the defined form size",
self::PARTIAL => "File was only partially uploaded",
self::NO_FILE => "File was not uploaded",
self::NO_TMP_DIR => "No temporary directory was found for file",
self::CANT_WRITE => "File can't be written",
self::EXTENSION => "A PHP extension returned an error while uploading the file",
self::ATTACK => "File was illegally uploaded. This could be a possible attack",
self::FILE_NOT_FOUND => "File was not found",
self::UNKNOWN => "Unknown error while uploading file",
self::INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
self::FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was '
. 'specified in the HTML form',
self::PARTIAL => 'The uploaded file was only partially uploaded',
self::NO_FILE => 'No file was uploaded',
self::NO_TMP_DIR => 'Missing a temporary folder',
self::CANT_WRITE => 'Failed to write file to disk',
self::EXTENSION => 'A PHP extension stopped the file upload',
self::ATTACK => 'File was illegally uploaded. This could be a possible attack',
self::FILE_NOT_FOUND => 'File was not found',
self::UNKNOWN => 'Unknown error while uploading file',
];
/**
* Returns true if and only if the file was uploaded without errors
*
* @param string $value File to check for upload errors
* @param string|array|UploadedFileInterface $value File to check for upload errors
* @return bool
* @throws Exception\InvalidArgumentException
*/
@@ -62,62 +64,106 @@ class UploadFile extends AbstractValidator
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
$error = $value['error'];
} else {
$file = $value;
$filename = basename($file);
$error = 0;
}
$this->setValue($filename);
return $this->validateUploadedFile(
$value['error'],
$value['name'],
$value['tmp_name']
);
}
if ($value instanceof UploadedFileInterface) {
return $this->validatePsr7UploadedFile($value);
}
if (is_string($value)) {
return $this->validateUploadedFile(0, basename($value), $value);
}
$this->error(self::UNKNOWN);
return false;
}
/**
* @param int $error UPLOAD_ERR_* constant value
* @return bool
*/
private function validateFileFromErrorCode($error)
{
switch ($error) {
case UPLOAD_ERR_OK:
if (empty($file) || false === is_file($file)) {
$this->error(self::FILE_NOT_FOUND);
} elseif (! is_uploaded_file($file)) {
$this->error(self::ATTACK);
}
break;
return true;
case UPLOAD_ERR_INI_SIZE:
$this->error(self::INI_SIZE);
break;
return false;
case UPLOAD_ERR_FORM_SIZE:
$this->error(self::FORM_SIZE);
break;
return false;
case UPLOAD_ERR_PARTIAL:
$this->error(self::PARTIAL);
break;
return false;
case UPLOAD_ERR_NO_FILE:
$this->error(self::NO_FILE);
break;
return false;
case UPLOAD_ERR_NO_TMP_DIR:
$this->error(self::NO_TMP_DIR);
break;
return false;
case UPLOAD_ERR_CANT_WRITE:
$this->error(self::CANT_WRITE);
break;
return false;
case UPLOAD_ERR_EXTENSION:
$this->error(self::EXTENSION);
break;
return false;
default:
$this->error(self::UNKNOWN);
break;
return false;
}
}
/**
* @param int $error UPLOAD_ERR_* constant
* @param string $filename
* @param string $uploadedFile Name of uploaded file (gen tmp_name)
* @return bool
*/
private function validateUploadedFile($error, $filename, $uploadedFile)
{
$this->setValue($filename);
// Normal errors can be validated normally
if ($error !== UPLOAD_ERR_OK) {
return $this->validateFileFromErrorCode($error);
}
if (count($this->getMessages()) > 0) {
// Did we get no name? Is the file missing?
if (empty($uploadedFile) || false === is_file($uploadedFile)) {
$this->error(self::FILE_NOT_FOUND);
return false;
}
// Do we have an invalid upload?
if (! is_uploaded_file($uploadedFile)) {
$this->error(self::ATTACK);
return false;
}
return true;
}
/**
* @return bool
*/
private function validatePsr7UploadedFile(UploadedFileInterface $uploadedFile)
{
$this->setValue($uploadedFile);
return $this->validateFileFromErrorCode($uploadedFile->getError());
}
}

View File

@@ -11,12 +11,15 @@ namespace Zend\Validator\File;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;
/**
* Validator for counting all words in a file
*/
class WordCount extends AbstractValidator
{
use FileInformationTrait;
/**
* @const string Error constants
*/
@@ -175,31 +178,17 @@ class WordCount extends AbstractValidator
*/
public function isValid($value, $file = null)
{
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);
$this->setValue($fileInfo['filename']);
// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}
$content = file_get_contents($file);
$content = file_get_contents($fileInfo['file']);
$this->count = str_word_count($content);
if (($this->getMax() !== null) && ($this->count > $this->getMax())) {
$this->error(self::TOO_MUCH);

View File

@@ -69,7 +69,7 @@ class Hostname extends AbstractValidator
/**
* Array of valid top-level-domains
* IanaVersion 2018013101
* IanaVersion 2019122700
*
* @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain
* @see http://www.iana.org/domains/root/db/ Official list of supported TLDs
@@ -92,7 +92,6 @@ class Hostname extends AbstractValidator
'accountant',
'accountants',
'aco',
'active',
'actor',
'ad',
'adac',
@@ -222,7 +221,6 @@ class Hostname extends AbstractValidator
'bj',
'black',
'blackfriday',
'blanco',
'blockbuster',
'blog',
'bloomberg',
@@ -231,7 +229,6 @@ class Hostname extends AbstractValidator
'bms',
'bmw',
'bn',
'bnl',
'bnpparibas',
'bo',
'boats',
@@ -242,7 +239,6 @@ class Hostname extends AbstractValidator
'boo',
'book',
'booking',
'boots',
'bosch',
'bostik',
'boston',
@@ -291,7 +287,6 @@ class Hostname extends AbstractValidator
'career',
'careers',
'cars',
'cartier',
'casa',
'case',
'caseih',
@@ -317,13 +312,13 @@ class Hostname extends AbstractValidator
'ch',
'chanel',
'channel',
'charity',
'chase',
'chat',
'cheap',
'chintai',
'christmas',
'chrome',
'chrysler',
'church',
'ci',
'cipriani',
@@ -375,6 +370,7 @@ class Hostname extends AbstractValidator
'coupon',
'coupons',
'courses',
'cpa',
'cr',
'credit',
'creditcard',
@@ -436,9 +432,7 @@ class Hostname extends AbstractValidator
'do',
'docs',
'doctor',
'dodge',
'dog',
'doha',
'domains',
'dot',
'download',
@@ -447,7 +441,6 @@ class Hostname extends AbstractValidator
'dubai',
'duck',
'dunlop',
'duns',
'dupont',
'durban',
'dvag',
@@ -468,7 +461,6 @@ class Hostname extends AbstractValidator
'engineer',
'engineering',
'enterprises',
'epost',
'epson',
'equipment',
'er',
@@ -484,7 +476,6 @@ class Hostname extends AbstractValidator
'eurovision',
'eus',
'events',
'everbank',
'exchange',
'expert',
'exposed',
@@ -564,6 +555,7 @@ class Hostname extends AbstractValidator
'games',
'gap',
'garden',
'gay',
'gb',
'gbiz',
'gd',
@@ -599,7 +591,6 @@ class Hostname extends AbstractValidator
'goldpoint',
'golf',
'goo',
'goodhands',
'goodyear',
'goog',
'google',
@@ -657,7 +648,6 @@ class Hostname extends AbstractValidator
'homes',
'homesense',
'honda',
'honeywell',
'horse',
'hospital',
'host',
@@ -691,6 +681,7 @@ class Hostname extends AbstractValidator
'immo',
'immobilien',
'in',
'inc',
'industries',
'infiniti',
'info',
@@ -710,7 +701,6 @@ class Hostname extends AbstractValidator
'ir',
'irish',
'is',
'iselect',
'ismaili',
'ist',
'istanbul',
@@ -718,7 +708,6 @@ class Hostname extends AbstractValidator
'itau',
'itv',
'iveco',
'iwc',
'jaguar',
'java',
'jcb',
@@ -728,7 +717,6 @@ class Hostname extends AbstractValidator
'jetzt',
'jewelry',
'jio',
'jlc',
'jll',
'jm',
'jmp',
@@ -777,12 +765,10 @@ class Hostname extends AbstractValidator
'kz',
'la',
'lacaixa',
'ladbrokes',
'lamborghini',
'lamer',
'lancaster',
'lancia',
'lancome',
'land',
'landrover',
'lanxess',
@@ -821,6 +807,8 @@ class Hostname extends AbstractValidator
'living',
'lixil',
'lk',
'llc',
'llp',
'loan',
'loans',
'locker',
@@ -875,7 +863,6 @@ class Hostname extends AbstractValidator
'memorial',
'men',
'menu',
'meo',
'merckmsd',
'metlife',
'mg',
@@ -897,7 +884,6 @@ class Hostname extends AbstractValidator
'mo',
'mobi',
'mobile',
'mobily',
'moda',
'moe',
'moi',
@@ -905,7 +891,6 @@ class Hostname extends AbstractValidator
'monash',
'money',
'monster',
'mopar',
'mormon',
'mortgage',
'moscow',
@@ -913,7 +898,6 @@ class Hostname extends AbstractValidator
'motorcycles',
'mov',
'movie',
'movistar',
'mp',
'mq',
'mr',
@@ -1011,7 +995,6 @@ class Hostname extends AbstractValidator
'pa',
'page',
'panasonic',
'panerai',
'paris',
'pars',
'partners',
@@ -1034,7 +1017,6 @@ class Hostname extends AbstractValidator
'photography',
'photos',
'physio',
'piaget',
'pics',
'pictet',
'pictures',
@@ -1150,7 +1132,6 @@ class Hostname extends AbstractValidator
'sandvikcoromant',
'sanofi',
'sap',
'sapo',
'sarl',
'sas',
'save',
@@ -1232,21 +1213,18 @@ class Hostname extends AbstractValidator
'sony',
'soy',
'space',
'spiegel',
'sport',
'spot',
'spreadbetting',
'sr',
'srl',
'srt',
'ss',
'st',
'stada',
'staples',
'star',
'starhub',
'statebank',
'statefarm',
'statoil',
'stc',
'stcgroup',
'stockholm',
@@ -1292,8 +1270,6 @@ class Hostname extends AbstractValidator
'tech',
'technology',
'tel',
'telecity',
'telefonica',
'temasek',
'tennis',
'teva',
@@ -1353,7 +1329,6 @@ class Hostname extends AbstractValidator
'ua',
'ubank',
'ubs',
'uconnect',
'ug',
'uk',
'unicom',
@@ -1387,7 +1362,6 @@ class Hostname extends AbstractValidator
'virgin',
'visa',
'vision',
'vista',
'vistaprint',
'viva',
'vivo',
@@ -1407,7 +1381,6 @@ class Hostname extends AbstractValidator
'walter',
'wang',
'wanggou',
'warman',
'watch',
'watches',
'weather',
@@ -1535,9 +1508,9 @@ class Hostname extends AbstractValidator
'اتصالات',
'امارات',
'بازار',
'موريتانيا',
'پاکستان',
'الاردن',
'موبايلي',
'بارت',
'بھارت',
'المغرب',
@@ -1569,6 +1542,7 @@ class Hostname extends AbstractValidator
'大拿',
'みんな',
'グーグル',
'ευ',
'ελ',
'世界',
'書籍',
@@ -1594,7 +1568,6 @@ class Hostname extends AbstractValidator
'新加坡',
'فلسطين',
'政务',
'xperia',
'xxx',
'xyz',
'yachts',
@@ -1614,7 +1587,6 @@ class Hostname extends AbstractValidator
'zara',
'zero',
'zip',
'zippo',
'zm',
'zone',
'zuerich',
@@ -1636,7 +1608,7 @@ class Hostname extends AbstractValidator
* (.CH) Switzerland https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
* (.CL) Chile http://www.iana.org/domains/idn-tables/tables/cl_latn_1.0.html
* (.COM) International http://www.verisign.com/information-services/naming-services/internationalized-domain-names/index.html
* (.DE) Germany http://www.denic.de/en/domains/idns/liste.html
* (.DE) Germany https://www.denic.de/en/know-how/idn-domains/idn-character-list/
* (.DK) Danmark http://www.dk-hostmaster.dk/index.php?id=151
* (.EE) Estonia https://www.iana.org/domains/idn-tables/tables/pl_et-pl_1.0.html
* (.ES) Spain https://www.nic.es/media/2008-05/1210147705287.pdf
@@ -1648,7 +1620,7 @@ class Hostname extends AbstractValidator
* (.INFO) International http://www.nic.info/info/idn
* (.IO) British Indian Ocean Territory http://www.nic.io/IO-IDN-Policy.pdf
* (.IR) Iran http://www.nic.ir/Allowable_Characters_dot-iran
* (.IS) Iceland http://www.isnic.is/domain/rules.php
* (.IS) Iceland https://www.isnic.is/en/domain/rules#2
* (.KR) Korea http://www.iana.org/domains/idn-tables/tables/kr_ko-kr_1.0.html
* (.LI) Liechtenstein https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
* (.LT) Lithuania http://www.domreg.lt/static/doc/public/idn_symbols-en.pdf
@@ -1689,7 +1661,7 @@ class Hostname extends AbstractValidator
'CL' => [1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'],
'CN' => 'Hostname/Cn.php',
'COM' => 'Hostname/Com.php',
'DE' => [1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'],
'DE' => [1 => '/^[\x{002d}0-9a-záàăâåäãąāæćĉčċçďđéèĕêěëėęēğĝġģĥħíìĭîïĩįīıĵķĺľļłńňñņŋóòŏôöőõøōœĸŕřŗśŝšşßťţŧúùŭûůüűũųūŵýŷÿźžżðþ]{1,63}$/iu'],
'DK' => [1 => '/^[\x{002d}0-9a-zäåæéöøü]{1,63}$/iu'],
'EE' => [1 => '/^[\x{002d}0-9a-zäõöüšž]{1,63}$/iu'],
'ES' => [1 => '/^[\x{002d}0-9a-zàáçèéíïñòóúü·]{1,63}$/iu'],
@@ -1769,6 +1741,7 @@ class Hostname extends AbstractValidator
33 => '/^[\x{002d}0-9א-ת]{1,63}$/iu'],
'PR' => [1 => '/^[\x{002d}0-9a-záéíóúñäëïüöâêîôûàèùæçœãõ]{1,63}$/iu'],
'PT' => [1 => '/^[\x{002d}0-9a-záàâãçéêíóôõú]{1,63}$/iu'],
'RS' => [1 => '/^[\x{002d}0-9a-zßáâäçéëíîóôöúüýăąćčďđęěĺľłńňőŕřśşšţťůűźżž]{1,63}$/iu'],
'RU' => [1 => '/^[\x{002d}0-9а-яё]{1,63}$/iu'],
'SA' => [1 => '/^[\x{002d}.0-9\x{0621}-\x{063A}\x{0641}-\x{064A}\x{0660}-\x{0669}]{1,63}$/iu'],
'SE' => [1 => '/^[\x{002d}0-9a-zäåéöü]{1,63}$/iu'],
@@ -2061,6 +2034,7 @@ class Hostname extends AbstractValidator
}
// Match TLD against known list
$removedTld = false;
if ($this->getTldCheck()) {
if (! in_array(strtolower($this->tld), $this->validTlds)
&& ! in_array($this->tld, $this->validTlds)) {
@@ -2071,6 +2045,7 @@ class Hostname extends AbstractValidator
// We have already validated that the TLD is fine. We don't want it to go through the below
// checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
array_pop($domainParts);
$removedTld = true;
}
/**
@@ -2090,6 +2065,10 @@ class Hostname extends AbstractValidator
// Check each hostname part
$check = 0;
$lastDomainPart = end($domainParts);
if (! $removedTld) {
$lastDomainPart = prev($domainParts);
}
foreach ($domainParts as $domainPart) {
// Decode Punycode domain names to IDN
if (strpos($domainPart, 'xn--') === 0) {
@@ -2099,6 +2078,13 @@ class Hostname extends AbstractValidator
}
}
// Skip following checks if domain part is empty, as it definitely is not a valid hostname then
if ($domainPart === '') {
$this->error(self::INVALID_HOSTNAME);
$status = false;
break 2;
}
// Check dash (-) does not start, end or appear in 3rd and 4th positions
if ($utf8StrWrapper->strpos($domainPart, '-') === 0
|| ($utf8StrWrapper->strlen($domainPart) > 2
@@ -2118,7 +2104,9 @@ class Hostname extends AbstractValidator
// Check each domain part
$checked = false;
foreach ($regexChars as $regexKey => $regexChar) {
$isSubDomain = $domainPart != $lastDomainPart;
$partRegexChars = $isSubDomain ? ['/^[a-z0-9_\x2d]{1,63}$/i'] + $regexChars : $regexChars;
foreach ($partRegexChars as $regexKey => $regexChar) {
$status = preg_match($regexChar, $domainPart);
if ($status > 0) {
$length = 63;

2
vendor/zendframework/zend-validator/src/Isbn/Isbn10.php vendored Normal file → Executable file
View File

@@ -32,7 +32,7 @@ class Isbn10
$sum = 0;
for ($i = 0; $i < 9; $i++) {
$sum += (10 - $i) * $value{$i};
$sum += (10 - $i) * $value[$i];
}
return $sum;

4
vendor/zendframework/zend-validator/src/Isbn/Isbn13.php vendored Normal file → Executable file
View File

@@ -33,11 +33,11 @@ class Isbn13
for ($i = 0; $i < 12; $i++) {
if ($i % 2 == 0) {
$sum += $value{$i};
$sum += $value[$i];
continue;
}
$sum += 3 * $value{$i};
$sum += 3 * $value[$i];
}
return $sum;

View File

@@ -122,7 +122,9 @@ class Step extends AbstractValidator
$this->setValue($value);
$fmod = $this->fmod($value - $this->baseValue, $this->step);
$substract = $this->sub($value, $this->baseValue);
$fmod = $this->fmod($substract, $this->step);
if ($fmod !== 0.0 && $fmod !== $this->step) {
$this->error(self::NOT_STEP);
@@ -146,10 +148,31 @@ class Step extends AbstractValidator
}
//find the maximum precision from both input params to give accurate results
$xFloatSegment = substr($x, strpos($x, '.') + 1) ?: '';
$yFloatSegment = substr($y, strpos($y, '.') + 1) ?: '';
$precision = strlen($xFloatSegment) + strlen($yFloatSegment);
$precision = $this->getPrecision($x) + $this->getPrecision($y);
return round($x - $y * floor($x / $y), $precision);
}
/**
* replaces the internal substraction operation which give wrong results on some cases
*
* @param float $x
* @param float $y
* @return float
*/
private function sub($x, $y)
{
$precision = $this->getPrecision($x) + $this->getPrecision($y);
return round($x - $y, $precision);
}
/**
* @param float $float
* @return int
*/
private function getPrecision($float)
{
$segment = substr($float, strpos($float, '.') + 1);
return $segment ? strlen($segment) : 0;
}
}

View File

@@ -226,7 +226,7 @@ class StringLength extends AbstractValidator
$this->error(self::TOO_LONG);
}
if (count($this->getMessages())) {
if ($this->getMessages()) {
return false;
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* @link http://github.com/zendframework/zend-validator for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Validator;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
final class UndisclosedPassword extends AbstractValidator
{
private const HIBP_API_URI = 'https://api.pwnedpasswords.com';
private const HIBP_API_REQUEST_TIMEOUT = 300;
private const HIBP_CLIENT_USER_AGENT_STRING = 'zend-validator';
private const HIBP_CLIENT_ACCEPT_HEADER = 'application/vnd.haveibeenpwned.v2+json';
private const HIBP_K_ANONYMITY_HASH_RANGE_LENGTH = 5;
private const HIBP_K_ANONYMITY_HASH_RANGE_BASE = 0;
private const SHA1_STRING_LENGTH = 40;
private const PASSWORD_BREACHED = 'passwordBreached';
private const NOT_A_STRING = 'wrongInput';
protected $messageTemplates = [
self::PASSWORD_BREACHED =>
'The provided password was found in previous breaches, please create another password',
self::NOT_A_STRING => 'The provided password is not a string, please provide a correct password',
];
/**
* @var ClientInterface
*/
private $httpClient;
/**
* @var RequestFactoryInterface
*/
private $makeHttpRequest;
/**
* @var ResponseFactoryInterface
*/
private $makeHttpResponse;
/**
* PasswordBreach constructor.
*/
public function __construct(
ClientInterface $httpClient,
RequestFactoryInterface $makeHttpRequest,
ResponseFactoryInterface $makeHttpResponse
) {
$this->httpClient = $httpClient;
$this->makeHttpRequest = $makeHttpRequest;
$this->makeHttpResponse = $makeHttpResponse;
}
/**
* @inheritDoc
*/
public function isValid($value)
{
if (! is_string($value)) {
$this->error(self::NOT_A_STRING);
return false;
}
if ($this->isPwnedPassword($value)) {
$this->error(self::PASSWORD_BREACHED);
return false;
}
return true;
}
private function isPwnedPassword(string $password) : bool
{
$sha1Hash = $this->hashPassword($password);
$rangeHash = $this->getRangeHash($sha1Hash);
$hashList = $this->retrieveHashList($rangeHash);
return $this->hashInResponse($sha1Hash, $hashList);
}
/**
* We use a SHA1 hashed password for checking it against
* the breached data set of HIBP.
*
* @param string $password
* @return string
*/
private function hashPassword(string $password) : string
{
$hashedPassword = \sha1($password);
return strtoupper($hashedPassword);
}
/**
* Creates a hash range that will be send to HIBP API
* applying K-Anonymity
*
* @param string $passwordHash
* @return string
* @see https://www.troyhunt.com/enhancing-pwned-passwords-privacy-by-exclusively-supporting-anonymity/
*/
private function getRangeHash(string $passwordHash) : string
{
return substr($passwordHash, self::HIBP_K_ANONYMITY_HASH_RANGE_BASE, self::HIBP_K_ANONYMITY_HASH_RANGE_LENGTH);
}
/**
* Making a connection to the HIBP API to retrieve a
* list of hashes that all have the same range as we
* provided.
*
* @param string $passwordRange
* @return string
* @throws ClientExceptionInterface
*/
private function retrieveHashList(string $passwordRange) : string
{
$request = $this->makeHttpRequest->createRequest(
'GET',
self::HIBP_API_URI . '/range/' . $passwordRange
);
$response = $this->httpClient->sendRequest($request);
return (string) $response->getBody();
}
/**
* Checks if the password is in the response from HIBP
*
* @param string $sha1Hash
* @param string $resultStream
* @return bool
*/
private function hashInResponse(string $sha1Hash, string $resultStream) : bool
{
$data = explode("\r\n", $resultStream);
$hashes = array_filter($data, function ($value) use ($sha1Hash) {
list($hash, $count) = explode(':', $value);
if (0 === strcmp($hash, substr($sha1Hash, self::HIBP_K_ANONYMITY_HASH_RANGE_LENGTH))) {
return true;
}
return false;
});
if ([] === $hashes) {
return false;
}
return true;
}
}