ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
HTMLPurifier_AttrDef_CSS_URI Class Reference

Validates a URI in CSS syntax, which uses url('http://example.com') More...

+ Inheritance diagram for HTMLPurifier_AttrDef_CSS_URI:
+ Collaboration diagram for HTMLPurifier_AttrDef_CSS_URI:

Public Member Functions

 __construct ()
 
 validate ($uri_string, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_AttrDef_URI
 __construct ($embeds_resource=false)
 
 make ($string)
 
 validate ($uri, $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
 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
 $parser
 HTMLPurifier_URIParser More...
 
 $embedsResource
 bool More...
 

Detailed Description

Validates a URI in CSS syntax, which uses url('http://example.com')

Note
While theoretically speaking a URI in a CSS document could be non-embedded, as of CSS2 there is no such usage so we're generalizing it. This may need to be changed in the future.
Warning
Since HTMLPurifier_AttrDef_CSS blindly uses semicolons as the separator, you cannot put a literal semicolon in in the URI. Try percent encoding it, in that case.

Definition at line 12 of file URI.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_AttrDef_CSS_URI::__construct ( )

Definition at line 15 of file URI.php.

16  {
17  parent::__construct(true); // always embedded
18  }

Member Function Documentation

◆ validate()

HTMLPurifier_AttrDef_CSS_URI::validate (   $uri_string,
  $config,
  $context 
)
Parameters
string$uri_string
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
bool|string

Definition at line 26 of file URI.php.

References $config, $result, array, HTMLPurifier_AttrDef\expandCSSEscape(), and HTMLPurifier_AttrDef\parseCDATA().

27  {
28  // parse the URI out of the string and then pass it onto
29  // the parent object
30 
31  $uri_string = $this->parseCDATA($uri_string);
32  if (strpos($uri_string, 'url(') !== 0) {
33  return false;
34  }
35  $uri_string = substr($uri_string, 4);
36  if (strlen($uri_string) == 0) {
37  return false;
38  }
39  $new_length = strlen($uri_string) - 1;
40  if ($uri_string[$new_length] != ')') {
41  return false;
42  }
43  $uri = trim(substr($uri_string, 0, $new_length));
44 
45  if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
46  $quote = $uri[0];
47  $new_length = strlen($uri) - 1;
48  if ($uri[$new_length] !== $quote) {
49  return false;
50  }
51  $uri = substr($uri, 1, $new_length - 1);
52  }
53 
54  $uri = $this->expandCSSEscape($uri);
55 
56  $result = parent::validate($uri, $config, $context);
57 
58  if ($result === false) {
59  return false;
60  }
61 
62  // extra sanity check; should have been done by URI
63  $result = str_replace(array('"', "\\", "\n", "\x0c", "\r"), "", $result);
64 
65  // suspicious characters are ()'; we're going to percent encode
66  // them for safety.
67  $result = str_replace(array('(', ')', "'"), array('%28', '%29', '%27'), $result);
68 
69  // there's an extra bug where ampersands lose their escaping on
70  // an innerHTML cycle, so a very unlucky query parameter could
71  // then change the meaning of the URL. Unfortunately, there's
72  // not much we can do about that...
73  return "url(\"$result\")";
74  }
$result
parseCDATA($string)
Convenience method that parses a string as if it were CDATA.
Definition: AttrDef.php:60
expandCSSEscape($string)
Parses a possibly escaped CSS string and returns the "pure" version of it.
Definition: AttrDef.php:96
Create styles array
The data for the language used.
+ Here is the call graph for this function:

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