00001 <?php 00002 00006 class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef 00007 { 00008 00012 protected $ipv4; 00013 00017 protected $ipv6; 00018 00019 public function __construct() { 00020 $this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4(); 00021 $this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6(); 00022 } 00023 00024 public function validate($string, $config, $context) { 00025 $length = strlen($string); 00026 if ($string === '') return ''; 00027 if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') { 00028 //IPv6 00029 $ip = substr($string, 1, $length - 2); 00030 $valid = $this->ipv6->validate($ip, $config, $context); 00031 if ($valid === false) return false; 00032 return '['. $valid . ']'; 00033 } 00034 00035 // need to do checks on unusual encodings too 00036 $ipv4 = $this->ipv4->validate($string, $config, $context); 00037 if ($ipv4 !== false) return $ipv4; 00038 00039 // A regular domain name. 00040 00041 // This breaks I18N domain names, but we don't have proper IRI support, 00042 // so force users to insert Punycode. If there's complaining we'll 00043 // try to fix things into an international friendly form. 00044 00045 // The productions describing this are: 00046 $a = '[a-z]'; // alpha 00047 $an = '[a-z0-9]'; // alphanum 00048 $and = '[a-z0-9-]'; // alphanum | "-" 00049 // domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum 00050 $domainlabel = "$an($and*$an)?"; 00051 // toplabel = alpha | alpha *( alphanum | "-" ) alphanum 00052 $toplabel = "$a($and*$an)?"; 00053 // hostname = *( domainlabel "." ) toplabel [ "." ] 00054 $match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string); 00055 if (!$match) return false; 00056 00057 return $string; 00058 } 00059 00060 } 00061 00062 // vim: et sw=4 sts=4
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
