Don't lower-case components of background.
[htmlpurifier.git] / tests / HTMLPurifier / URISchemeTest.php
blobcbd4fc58b85ba705ad9eab3af2a31fac5e2bde5f
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() {
12 $this->pngBase64 =
13 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP'.
14 'C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA'.
15 'AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J'.
16 'REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq'.
17 'ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0'.
18 'vr4MkhoXe0rZigAAAABJRU5ErkJggg==';
21 protected function assertValidation($uri, $expect_uri = true) {
22 $this->prepareURI($uri, $expect_uri);
23 $this->config->set('URI.AllowedSchemes', array($uri->scheme));
24 // convenience hack: the scheme should be explicitly specified
25 $scheme = $uri->getSchemeObj($this->config, $this->context);
26 $result = $scheme->validate($uri, $this->config, $this->context);
27 $this->assertEitherFailOrIdentical($result, $uri, $expect_uri);
30 function test_http_regular() {
31 $this->assertValidation(
32 'http://example.com/?s=q#fragment'
36 function test_http_uppercase() {
37 $this->assertValidation(
38 'http://example.com/FOO'
42 function test_http_removeDefaultPort() {
43 $this->assertValidation(
44 'http://example.com:80',
45 'http://example.com'
49 function test_http_removeUserInfo() {
50 $this->assertValidation(
51 'http://bob@example.com',
52 'http://example.com'
56 function test_http_preserveNonDefaultPort() {
57 $this->assertValidation(
58 'http://example.com:8080'
62 function test_https_regular() {
63 $this->assertValidation(
64 'https://user@example.com:443/?s=q#frag',
65 'https://example.com/?s=q#frag'
69 function test_ftp_regular() {
70 $this->assertValidation(
71 'ftp://user@example.com/path'
75 function test_ftp_removeDefaultPort() {
76 $this->assertValidation(
77 'ftp://example.com:21',
78 'ftp://example.com'
82 function test_ftp_removeQueryString() {
83 $this->assertValidation(
84 'ftp://example.com?s=q',
85 'ftp://example.com'
89 function test_ftp_preserveValidTypecode() {
90 $this->assertValidation(
91 'ftp://example.com/file.txt;type=a'
95 function test_ftp_removeInvalidTypecode() {
96 $this->assertValidation(
97 'ftp://example.com/file.txt;type=z',
98 'ftp://example.com/file.txt'
102 function test_ftp_encodeExtraSemicolons() {
103 $this->assertValidation(
104 'ftp://example.com/too;many;semicolons=1',
105 'ftp://example.com/too%3Bmany%3Bsemicolons=1'
109 function test_news_regular() {
110 $this->assertValidation(
111 'news:gmane.science.linguistics'
115 function test_news_explicit() {
116 $this->assertValidation(
117 'news:642@eagle.ATT.COM'
121 function test_news_removeNonPathComponents() {
122 $this->assertValidation(
123 'news://user@example.com:80/rec.music?path=foo#frag',
124 'news:/rec.music#frag'
128 function test_nntp_regular() {
129 $this->assertValidation(
130 'nntp://news.example.com/alt.misc/42#frag'
134 function test_nntp_removalOfRedundantOrUselessComponents() {
135 $this->assertValidation(
136 'nntp://user@news.example.com:119/alt.misc/42?s=q#frag',
137 'nntp://news.example.com/alt.misc/42#frag'
141 function test_mailto_regular() {
142 $this->assertValidation(
143 'mailto:bob@example.com'
147 function test_mailto_removalOfRedundantOrUselessComponents() {
148 $this->assertValidation(
149 'mailto://user@example.com:80/bob@example.com?subject=Foo#frag',
150 'mailto:/bob@example.com?subject=Foo#frag'
154 function test_data_png() {
155 $this->assertValidation(
156 'data:image/png;base64,'.$this->pngBase64
160 function test_data_malformed() {
161 $this->assertValidation(
162 'data:image/png;base64,vr4MkhoXJRU5ErkJggg==',
163 false
167 function test_data_implicit() {
168 $this->assertValidation(
169 'data:base64,'.$this->pngBase64,
170 'data:image/png;base64,'.$this->pngBase64
174 function test_file_basic() {
175 $this->assertValidation(
176 'file://user@MYCOMPUTER:12/foo/bar?baz#frag',
177 'file://MYCOMPUTER/foo/bar#frag'
181 function test_file_local() {
182 $this->assertValidation(
183 'file:///foo/bar?baz#frag',
184 'file:///foo/bar#frag'
188 function test_ftp_empty_host() {
189 $this->assertValidation('ftp:///example.com', false);
194 // vim: et sw=4 sts=4