Source for file Host.php
Documentation is available at Host.php
* Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
* Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
* Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
public function validate($string, $config, $context) {
if ($string ===
'') return '';
if ($length >
1 &&
$string[0] ===
'[' &&
$string[$length-
1] ===
']') {
$ip =
substr($string, 1, $length -
2);
$valid =
$this->ipv6->validate($ip, $config, $context);
if ($valid ===
false) return false;
return '['.
$valid .
']';
// need to do checks on unusual encodings too
$ipv4 =
$this->ipv4->validate($string, $config, $context);
if ($ipv4 !==
false) return $ipv4;
// A regular domain name.
// This breaks I18N domain names, but we don't have proper IRI support,
// so force users to insert Punycode. If there's complaining we'll
// try to fix things into an international friendly form.
// The productions describing this are:
$an =
'[a-z0-9]'; // alphanum
$and =
'[a-z0-9-]'; // alphanum | "-"
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
$domainlabel =
"$an($and*$an)?";
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
$toplabel =
"$a($and*$an)?";
// hostname = *( domainlabel "." ) toplabel [ "." ]
$match =
preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string);
if (!$match) return false;
Documentation generated on Thu, 19 Jun 2008 18:49:17 -0400 by phpDocumentor 1.4.2