4 * Validates a URI as defined by RFC 3986.
5 * @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme
7 class HTMLPurifier_AttrDef_URI
extends HTMLPurifier_AttrDef
11 protected $embedsResource;
14 * @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
16 public function __construct($embeds_resource = false) {
17 $this->parser
= new HTMLPurifier_URIParser();
18 $this->embedsResource
= (bool) $embeds_resource;
21 public function make($string) {
22 $embeds = (bool) $string;
23 return new HTMLPurifier_AttrDef_URI($embeds);
26 public function validate($uri, $config, $context) {
28 if ($config->get('URI', 'Disable')) return false;
30 $uri = $this->parseCDATA($uri);
33 $uri = $this->parser
->parse($uri);
34 if ($uri === false) return false;
36 // add embedded flag to context for validators
37 $context->register('EmbeddedURI', $this->embedsResource
);
43 $result = $uri->validate($config, $context);
47 $uri_def = $config->getDefinition('URI');
48 $result = $uri_def->filter($uri, $config, $context);
51 // scheme-specific validation
52 $scheme_obj = $uri->getSchemeObj($config, $context);
53 if (!$scheme_obj) break;
54 if ($this->embedsResource
&& !$scheme_obj->browsable
) break;
55 $result = $scheme_obj->validate($uri, $config, $context);
58 // Post chained filtering
59 $result = $uri_def->postFilter($uri, $config, $context);
67 $context->destroy('EmbeddedURI');
68 if (!$ok) return false;
71 return $uri->toString();