import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -14,9 +14,9 @@
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hostname.php 14556 2009-03-31 10:35:42Z thomas $
|
||||
* @version $Id: Hostname.php 17141 2009-07-26 12:49:17Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -24,11 +24,6 @@
|
||||
*/
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Ip
|
||||
*/
|
||||
@ -46,11 +41,12 @@ require_once 'Zend/Validate/Ip.php';
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
{
|
||||
const INVALID = 'hostnameInvalid';
|
||||
const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed';
|
||||
const UNKNOWN_TLD = 'hostnameUnknownTld';
|
||||
const INVALID_DASH = 'hostnameDashCharacter';
|
||||
@ -65,6 +61,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
* @var array
|
||||
*/
|
||||
protected $_messageTemplates = array(
|
||||
self::INVALID => "Invalid type given, value should be a string",
|
||||
self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
|
||||
self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list",
|
||||
self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position",
|
||||
@ -414,27 +411,34 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
$valueString = (string) $value;
|
||||
if (!is_string($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_setValue($valueString);
|
||||
$this->_setValue($value);
|
||||
|
||||
// Check input against IP address schema
|
||||
if ($this->_ipValidator->setTranslator($this->getTranslator())->isValid($valueString)) {
|
||||
if (preg_match('/^[0-9.a-e:.]*$/i', $value) &&
|
||||
$this->_ipValidator->setTranslator($this->getTranslator())->isValid($value)) {
|
||||
if (!($this->_allow & self::ALLOW_IP)) {
|
||||
$this->_error(self::IP_ADDRESS_NOT_ALLOWED);
|
||||
return false;
|
||||
} else{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check input against DNS hostname schema
|
||||
$domainParts = explode('.', $valueString);
|
||||
if ((count($domainParts) > 1) && (strlen($valueString) >= 4) && (strlen($valueString) <= 254)) {
|
||||
$domainParts = explode('.', $value);
|
||||
if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
|
||||
$status = false;
|
||||
|
||||
$origenc = iconv_get_encoding('internal_encoding');
|
||||
iconv_set_encoding('internal_encoding', 'UTF-8');
|
||||
do {
|
||||
// First check TLD
|
||||
$matches = array();
|
||||
if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) ||
|
||||
(end($domainParts) == 'ایران') || (end($domainParts) == '中国') ||
|
||||
(end($domainParts) == '公司') || (end($domainParts) == '网络')) {
|
||||
@ -496,6 +500,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
foreach($regexChars as $regexKey => $regexChar) {
|
||||
$status = @preg_match($regexChar, $domainPart);
|
||||
if ($status === false) {
|
||||
iconv_set_encoding('internal_encoding', $origenc);
|
||||
require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Internal error: DNS validation failed');
|
||||
} elseif ($status !== 0) {
|
||||
@ -505,7 +510,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
$length = $this->_idnLength[strtoupper($this->_tld)];
|
||||
}
|
||||
|
||||
if (iconv_strlen($domainPart) > $length) {
|
||||
if (iconv_strlen($domainPart, 'UTF-8') > $length) {
|
||||
$this->_error(self::INVALID_HOSTNAME);
|
||||
} else {
|
||||
$check = true;
|
||||
@ -532,6 +537,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
}
|
||||
} while (false);
|
||||
|
||||
iconv_set_encoding('internal_encoding', $origenc);
|
||||
// If the input passes as an Internet domain name, and domain names are allowed, then the hostname
|
||||
// passes validation
|
||||
if ($status && ($this->_allow & self::ALLOW_DNS)) {
|
||||
@ -543,7 +549,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
|
||||
// Check input against local network name schema; last chance to pass validation
|
||||
$regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/';
|
||||
$status = @preg_match($regexLocal, $valueString);
|
||||
$status = @preg_match($regexLocal, $value);
|
||||
if (false === $status) {
|
||||
/**
|
||||
* Regex error
|
||||
@ -582,9 +588,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
|
||||
*/
|
||||
protected function decodePunycode($encoded)
|
||||
{
|
||||
$matches = array();
|
||||
$found = preg_match('/([^a-z0-9\x2d]{1,10})$/i', $encoded);
|
||||
if (empty($encoded) || (count($matches) > 0)) {
|
||||
$found = preg_match('/([^a-z0-9\x2d]{1,10})$/i', $encoded);
|
||||
if (empty($encoded) || ($found > 0)) {
|
||||
// no punycode encoded string, return as is
|
||||
$this->_error(self::CANNOT_DECODE_PUNYCODE);
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user