3 require_once 'HTMLPurifier/AttrDef.php';
4 require_once 'HTMLPurifier/AttrDef/IPv4.php';
5 require_once 'HTMLPurifier/AttrDef/IPv6.php';
7 class HTMLPurifier_AttrDef_Host
extends HTMLPurifier_AttrDef
12 function HTMLPurifier_AttrDef_Host() {
13 $this->ipv4
= new HTMLPurifier_AttrDef_IPv4();
14 $this->ipv6
= new HTMLPurifier_AttrDef_IPv6();
17 function validate($string, $config, &$context) {
18 $length = strlen($string);
19 if ($string === '') return '';
20 if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
22 $ip = substr($string, 1, $length - 2);
23 $valid = $this->ipv6
->validate($ip, $config, $context);
24 if ($valid === false) return false;
25 return '['. $valid . ']';
27 $ipv4 = $this->ipv4
->validate($string, $config, $context);
28 if ($ipv4 !== false) return $ipv4;
30 // validate a domain name here, do filtering, etc etc etc
32 // We could use this, but it would break I18N domain names
33 //$match = preg_match('/^[a-z0-9][\w\-\.]*[a-z0-9]$/i', $string);
34 //if (!$match) return false;