ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
URIScheme.php
Go to the documentation of this file.
1 <?php
2 
6 abstract class HTMLPurifier_URIScheme
7 {
8 
14  public $default_port = null;
15 
20  public $browsable = false;
21 
26  public $hierarchical = false;
27 
33  public $may_omit_host = false;
34 
42  public abstract function doValidate(&$uri, $config, $context);
43 
52  public function validate(&$uri, $config, $context) {
53  if ($this->default_port == $uri->port) $uri->port = null;
54  // kludge: browsers do funny things when the scheme but not the
55  // authority is set
56  if (!$this->may_omit_host &&
57  // if the scheme is present, a missing host is always in error
58  (!is_null($uri->scheme) && ($uri->host === '' || is_null($uri->host))) ||
59  // if the scheme is not present, a *blank* host is in error,
60  // since this translates into '///path' which most browsers
61  // interpret as being 'http://path'.
62  (is_null($uri->scheme) && $uri->host === '')
63  ) {
64  do {
65  if (is_null($uri->scheme)) {
66  if (substr($uri->path, 0, 2) != '//') {
67  $uri->host = null;
68  break;
69  }
70  // URI is '////path', so we cannot nullify the
71  // host to preserve semantics. Try expanding the
72  // hostname instead (fall through)
73  }
74  // first see if we can manually insert a hostname
75  $host = $config->get('URI.Host');
76  if (!is_null($host)) {
77  $uri->host = $host;
78  } else {
79  // we can't do anything sensible, reject the URL.
80  return false;
81  }
82  } while (false);
83  }
84  return $this->doValidate($uri, $config, $context);
85  }
86 
87 }
88 
89 // vim: et sw=4 sts=4