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 * @type HTMLPurifier_URIParser
18 protected $embedsResource;
21 * @param bool $embeds_resource Does the URI here result in an extra HTTP request?
23 public function __construct($embeds_resource = false)
25 $this->parser
= new HTMLPurifier_URIParser();
26 $this->embedsResource
= (bool)$embeds_resource;
30 * @param string $string
31 * @return HTMLPurifier_AttrDef_URI
33 public function make($string)
35 $embeds = ($string === 'embedded');
36 return new HTMLPurifier_AttrDef_URI($embeds);
41 * @param HTMLPurifier_Config $config
42 * @param HTMLPurifier_Context $context
45 public function validate($uri, $config, $context)
47 if ($config->get('URI.Disable')) {
51 $uri = $this->parseCDATA($uri);
54 $uri = $this->parser
->parse($uri);
59 // add embedded flag to context for validators
60 $context->register('EmbeddedURI', $this->embedsResource
);
66 $result = $uri->validate($config, $context);
72 $uri_def = $config->getDefinition('URI');
73 $result = $uri_def->filter($uri, $config, $context);
78 // scheme-specific validation
79 $scheme_obj = $uri->getSchemeObj($config, $context);
83 if ($this->embedsResource
&& !$scheme_obj->browsable
) {
86 $result = $scheme_obj->validate($uri, $config, $context);
91 // Post chained filtering
92 $result = $uri_def->postFilter($uri, $config, $context);
102 $context->destroy('EmbeddedURI');
107 return $uri->toString();
111 // vim: et sw=4 sts=4