1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
- {
-
- protected $ipv4;
-
- protected $ipv6;
- public function __construct() {
- $this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
- $this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
- }
- public function validate($string, $config, $context) {
- $length = strlen($string);
- 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 . ']';
- }
-
- $ipv4 = $this->ipv4->validate($string, $config, $context);
- if ($ipv4 !== false) return $ipv4;
-
-
-
-
-
- $a = '[a-z]';
- $an = '[a-z0-9]';
- $and = '[a-z0-9-]';
-
- $domainlabel = "$an($and*$an)?";
-
- $toplabel = "$a($and*$an)?";
-
- $match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string);
- if (!$match) return false;
- return $string;
- }
- }
|