ILIAS  release_4-4 Revision
HTMLPurifier_AttrDef_URI_IPv6 Class Reference

Validates an IPv6 address. More...

+ Inheritance diagram for HTMLPurifier_AttrDef_URI_IPv6:
+ Collaboration diagram for HTMLPurifier_AttrDef_URI_IPv6:

Public Member Functions

 validate ($aIP, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef_URI_IPv4
 validate ($aIP, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef
 validate ($string, $config, $context)
 Validates and cleans passed string according to a definition. More...
 
 parseCDATA ($string)
 Convenience method that parses a string as if it were CDATA. More...
 
 make ($string)
 Factory method for creating this class from a string. More...
 

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_AttrDef
 $minimized = false
 Tells us whether or not an HTML attribute is minimized. More...
 
 $required = false
 Tells us whether or not an HTML attribute is required. More...
 
- Protected Member Functions inherited from HTMLPurifier_AttrDef_URI_IPv4
 _loadRegex ()
 Lazy load function to prevent regex from being stuffed in cache. More...
 
- Protected Member Functions inherited from HTMLPurifier_AttrDef
 mungeRgb ($string)
 Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
 
 expandCSSEscape ($string)
 Parses a possibly escaped CSS string and returns the "pure" version of it. More...
 
- Protected Attributes inherited from HTMLPurifier_AttrDef_URI_IPv4
 $ip4
 IPv4 regex, protected so that IPv6 can reuse it. More...
 

Detailed Description

Validates an IPv6 address.

Author
Feyd @ forums.devnetwork.net (public domain)
Note
This function requires brackets to have been removed from address in URI.

Definition at line 9 of file IPv6.php.

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_URI_IPv6::validate (   $aIP,
  $config,
  $context 
)

Definition at line 12 of file IPv6.php.

References HTMLPurifier_AttrDef_URI_IPv4\_loadRegex().

12  {
13 
14  if (!$this->ip4) $this->_loadRegex();
15 
16  $original = $aIP;
17 
18  $hex = '[0-9a-fA-F]';
19  $blk = '(?:' . $hex . '{1,4})';
20  $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128
21 
22  // prefix check
23  if (strpos($aIP, '/') !== false)
24  {
25  if (preg_match('#' . $pre . '$#s', $aIP, $find))
26  {
27  $aIP = substr($aIP, 0, 0-strlen($find[0]));
28  unset($find);
29  }
30  else
31  {
32  return false;
33  }
34  }
35 
36  // IPv4-compatiblity check
37  if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
38  {
39  $aIP = substr($aIP, 0, 0-strlen($find[0]));
40  $ip = explode('.', $find[0]);
41  $ip = array_map('dechex', $ip);
42  $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
43  unset($find, $ip);
44  }
45 
46  // compression check
47  $aIP = explode('::', $aIP);
48  $c = count($aIP);
49  if ($c > 2)
50  {
51  return false;
52  }
53  elseif ($c == 2)
54  {
55  list($first, $second) = $aIP;
56  $first = explode(':', $first);
57  $second = explode(':', $second);
58 
59  if (count($first) + count($second) > 8)
60  {
61  return false;
62  }
63 
64  while(count($first) < 8)
65  {
66  array_push($first, '0');
67  }
68 
69  array_splice($first, 8 - count($second), 8, $second);
70  $aIP = $first;
71  unset($first,$second);
72  }
73  else
74  {
75  $aIP = explode(':', $aIP[0]);
76  }
77  $c = count($aIP);
78 
79  if ($c != 8)
80  {
81  return false;
82  }
83 
84  // All the pieces should be 16-bit hex strings. Are they?
85  foreach ($aIP as $piece)
86  {
87  if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
88  {
89  return false;
90  }
91  }
92 
93  return $original;
94 
95  }
_loadRegex()
Lazy load function to prevent regex from being stuffed in cache.
Definition: IPv4.php:32
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: