3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/URI/IPv4.php';
5 require_once 'HTMLPurifier/AttrDef/URI/IPv6.php';
8 * Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
10 class HTMLPurifier_AttrDef_URI_Host
extends HTMLPurifier_AttrDef
14 * Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
19 * Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
23 function HTMLPurifier_AttrDef_URI_Host() {
24 $this->ipv4
= new HTMLPurifier_AttrDef_URI_IPv4();
25 $this->ipv6
= new HTMLPurifier_AttrDef_URI_IPv6();
28 function validate($string, $config, &$context) {
29 $length = strlen($string);
30 if ($string === '') return '';
31 if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
33 $ip = substr($string, 1, $length - 2);
34 $valid = $this->ipv6
->validate($ip, $config, $context);
35 if ($valid === false) return false;
36 return '['. $valid . ']';
39 // need to do checks on unusual encodings too
40 $ipv4 = $this->ipv4
->validate($string, $config, $context);
41 if ($ipv4 !== false) return $ipv4;
43 // validate a domain name here, do filtering, etc etc etc
45 // We could use this, but it would break I18N domain names
46 //$match = preg_match('/^[a-z0-9][\w\-\.]*[a-z0-9]$/i', $string);
47 //if (!$match) return false;