Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / tests / HTMLPurifier / URISchemeTest.php
blobcae6edd05d47d89beab8604a99dfe4ebdf79964e
1 <?php
3 // WARNING: All the URI schemes are far to relaxed, we need to tighten
4 // the checks.
6 class HTMLPurifier_URISchemeTest extends HTMLPurifier_URIHarness
9 private $pngBase64;
11 public function __construct()
13 $this->pngBase64 =
14 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP'.
15 'C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA'.
16 'AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J'.
17 'REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq'.
18 'ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0'.
19 'vr4MkhoXe0rZigAAAABJRU5ErkJggg==';
22 protected function assertValidation($uri, $expect_uri = true)
24 $this->prepareURI($uri, $expect_uri);
25 $this->config->set('URI.AllowedSchemes', array($uri->scheme));
26 // convenience hack: the scheme should be explicitly specified
27 $scheme = $uri->getSchemeObj($this->config, $this->context);
28 $result = $scheme->validate($uri, $this->config, $this->context);
29 $this->assertEitherFailOrIdentical($result, $uri, $expect_uri);
32 public function test_http_regular()
34 $this->assertValidation(
35 'http://example.com/?s=q#fragment'
39 public function test_http_uppercase()
41 $this->assertValidation(
42 'http://example.com/FOO'
46 public function test_http_removeDefaultPort()
48 $this->assertValidation(
49 'http://example.com:80',
50 'http://example.com'
54 public function test_http_removeUserInfo()
56 $this->assertValidation(
57 'http://bob@example.com',
58 'http://example.com'
62 public function test_http_preserveNonDefaultPort()
64 $this->assertValidation(
65 'http://example.com:8080'
69 public function test_https_regular()
71 $this->assertValidation(
72 'https://user@example.com:443/?s=q#frag',
73 'https://example.com/?s=q#frag'
77 public function test_ftp_regular()
79 $this->assertValidation(
80 'ftp://user@example.com/path'
84 public function test_ftp_removeDefaultPort()
86 $this->assertValidation(
87 'ftp://example.com:21',
88 'ftp://example.com'
92 public function test_ftp_removeQueryString()
94 $this->assertValidation(
95 'ftp://example.com?s=q',
96 'ftp://example.com'
100 public function test_ftp_preserveValidTypecode()
102 $this->assertValidation(
103 'ftp://example.com/file.txt;type=a'
107 public function test_ftp_removeInvalidTypecode()
109 $this->assertValidation(
110 'ftp://example.com/file.txt;type=z',
111 'ftp://example.com/file.txt'
115 public function test_ftp_encodeExtraSemicolons()
117 $this->assertValidation(
118 'ftp://example.com/too;many;semicolons=1',
119 'ftp://example.com/too%3Bmany%3Bsemicolons=1'
123 public function test_news_regular()
125 $this->assertValidation(
126 'news:gmane.science.linguistics'
130 public function test_news_explicit()
132 $this->assertValidation(
133 'news:642@eagle.ATT.COM'
137 public function test_news_removeNonPathComponents()
139 $this->assertValidation(
140 'news://user@example.com:80/rec.music?path=foo#frag',
141 'news:/rec.music#frag'
145 public function test_nntp_regular()
147 $this->assertValidation(
148 'nntp://news.example.com/alt.misc/42#frag'
152 public function test_nntp_removalOfRedundantOrUselessComponents()
154 $this->assertValidation(
155 'nntp://user@news.example.com:119/alt.misc/42?s=q#frag',
156 'nntp://news.example.com/alt.misc/42#frag'
160 public function test_mailto_regular()
162 $this->assertValidation(
163 'mailto:bob@example.com'
167 public function test_mailto_removalOfRedundantOrUselessComponents()
169 $this->assertValidation(
170 'mailto://user@example.com:80/bob@example.com?subject=Foo#frag',
171 'mailto:/bob@example.com?subject=Foo#frag'
175 public function test_tel_strip_punctuation()
177 $this->assertValidation(
178 'tel:+1 (555) 555-5555', 'tel:+15555555555'
182 public function test_tel_regular()
184 $this->assertValidation(
185 'tel:+15555555555'
189 public function test_tel_with_extension()
191 $this->assertValidation(
192 'tel:+1-555-555-5555x123', 'tel:+15555555555x123'
196 public function test_tel_no_plus()
198 $this->assertValidation(
199 'tel:555-555-5555', 'tel:5555555555'
203 public function test_tel_strip_letters()
205 $this->assertValidation(
206 'tel:abcd1234',
207 'tel:1234'
211 public function test_data_png()
213 $this->assertValidation(
214 'data:image/png;base64,'.$this->pngBase64
218 public function test_data_malformed()
220 $this->assertValidation(
221 'data:image/png;base64,vr4MkhoXJRU5ErkJggg==',
222 false
226 public function test_data_implicit()
228 $this->assertValidation(
229 'data:base64,'.$this->pngBase64,
230 'data:image/png;base64,'.$this->pngBase64
234 public function test_file_basic()
236 $this->assertValidation(
237 'file://user@MYCOMPUTER:12/foo/bar?baz#frag',
238 'file://MYCOMPUTER/foo/bar#frag'
242 public function test_file_local()
244 $this->assertValidation(
245 'file:///foo/bar?baz#frag',
246 'file:///foo/bar#frag'
250 public function test_ftp_empty_host()
252 $this->assertValidation('ftp:///example.com', false);
255 public function test_data_bad_base64()
257 $this->assertValidation('data:image/png;base64,aGVsbG90aGVyZXk|', false);
260 public function test_data_too_short()
262 $this->assertValidation('data:image/png;base64,aGVsbG90aGVyZXk=', false);
267 // vim: et sw=4 sts=4