File indexing completed on 2025-02-02 05:43:42
0001 <?php 0002 0003 /** 0004 * Validates an IPv4 address 0005 * @author Feyd @ forums.devnetwork.net (public domain) 0006 */ 0007 class HTMLPurifier_AttrDef_URI_IPv4 extends HTMLPurifier_AttrDef 0008 { 0009 0010 /** 0011 * IPv4 regex, protected so that IPv6 can reuse it. 0012 * @type string 0013 */ 0014 protected $ip4; 0015 0016 /** 0017 * @param string $aIP 0018 * @param HTMLPurifier_Config $config 0019 * @param HTMLPurifier_Context $context 0020 * @return bool|string 0021 */ 0022 public function validate($aIP, $config, $context) 0023 { 0024 if (!$this->ip4) { 0025 $this->_loadRegex(); 0026 } 0027 0028 if (preg_match('#^' . $this->ip4 . '$#s', $aIP)) { 0029 return $aIP; 0030 } 0031 return false; 0032 } 0033 0034 /** 0035 * Lazy load function to prevent regex from being stuffed in 0036 * cache. 0037 */ 0038 protected function _loadRegex() 0039 { 0040 $oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255 0041 $this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})"; 0042 } 0043 } 0044 0045 // vim: et sw=4 sts=4