1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: |
|
12: | class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
|
13: | {
|
14: |
|
15: | public function __construct()
|
16: | {
|
17: | parent::__construct(true);
|
18: | }
|
19: |
|
20: | |
21: | |
22: | |
23: | |
24: | |
25: |
|
26: | public function validate($uri_string, $config, $context)
|
27: | {
|
28: |
|
29: |
|
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: |
|
63: | $result = str_replace(array('"', "\\", "\n", "\x0c", "\r"), "", $result);
|
64: |
|
65: |
|
66: |
|
67: | $result = str_replace(array('(', ')', "'"), array('%28', '%29', '%27'), $result);
|
68: |
|
69: |
|
70: |
|
71: |
|
72: |
|
73: | return "url(\"$result\")";
|
74: | }
|
75: | }
|
76: |
|
77: |
|
78: | |