Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / URISchemeTest.php
blob6f43d10c5648d9d95d4bd5e40c95b5611e99b453
1 <?php
3 require_once 'HTMLPurifier/URI.php';
5 require_once 'HTMLPurifier/URIScheme.php';
6 require_once 'HTMLPurifier/URISchemeRegistry.php';
8 require_once 'HTMLPurifier/URIScheme/http.php';
9 require_once 'HTMLPurifier/URIScheme/ftp.php';
10 require_once 'HTMLPurifier/URIScheme/https.php';
11 require_once 'HTMLPurifier/URIScheme/mailto.php';
12 require_once 'HTMLPurifier/URIScheme/news.php';
13 require_once 'HTMLPurifier/URIScheme/nntp.php';
15 // WARNING: All the URI schemes are far to relaxed, we need to tighten
16 // the checks.
18 class HTMLPurifier_URISchemeTest extends HTMLPurifier_URIHarness
21 function assertValidation($uri, $expect_uri = true) {
22 $this->prepareURI($uri, $expect_uri);
23 // convenience hack: the scheme should be explicitly specified
24 $scheme = $uri->getSchemeObj($this->config, $this->context);
25 $result = $scheme->validate($uri, $this->config, $this->context);
26 $this->assertEitherFailOrIdentical($result, $uri, $expect_uri);
29 function test_http_regular() {
30 $this->assertValidation(
31 'http://example.com/?s=q#fragment'
35 function test_http_removeDefaultPort() {
36 $this->assertValidation(
37 'http://example.com:80',
38 'http://example.com'
42 function test_http_removeUserInfo() {
43 $this->assertValidation(
44 'http://bob@example.com',
45 'http://example.com'
49 function test_http_preserveNonDefaultPort() {
50 $this->assertValidation(
51 'http://example.com:8080'
55 function test_https_regular() {
56 $this->assertValidation(
57 'https://user@example.com:443/?s=q#frag',
58 'https://example.com/?s=q#frag'
62 function test_ftp_regular() {
63 $this->assertValidation(
64 'ftp://user@example.com/path'
68 function test_ftp_removeDefaultPort() {
69 $this->assertValidation(
70 'ftp://example.com:21',
71 'ftp://example.com'
75 function test_ftp_removeQueryString() {
76 $this->assertValidation(
77 'ftp://example.com?s=q',
78 'ftp://example.com'
82 function test_ftp_preserveValidTypecode() {
83 $this->assertValidation(
84 'ftp://example.com/file.txt;type=a'
88 function test_ftp_removeInvalidTypecode() {
89 $this->assertValidation(
90 'ftp://example.com/file.txt;type=z',
91 'ftp://example.com/file.txt'
95 function test_ftp_encodeExtraSemicolons() {
96 $this->assertValidation(
97 'ftp://example.com/too;many;semicolons=1',
98 'ftp://example.com/too%3Bmany%3Bsemicolons=1'
102 function test_news_regular() {
103 $this->assertValidation(
104 'news:gmane.science.linguistics'
108 function test_news_explicit() {
109 $this->assertValidation(
110 'news:642@eagle.ATT.COM'
114 function test_news_removeNonPathComponents() {
115 $this->assertValidation(
116 'news://user@example.com:80/rec.music?path=foo#frag',
117 'news:/rec.music#frag'
121 function test_nntp_regular() {
122 $this->assertValidation(
123 'nntp://news.example.com/alt.misc/42#frag'
127 function test_nntp_removalOfRedundantOrUselessComponents() {
128 $this->assertValidation(
129 'nntp://user@news.example.com:119/alt.misc/42?s=q#frag',
130 'nntp://news.example.com/alt.misc/42#frag'
134 function test_mailto_regular() {
135 $this->assertValidation(
136 'mailto:bob@example.com'
140 function test_mailto_removalOfRedundantOrUselessComponents() {
141 $this->assertValidation(
142 'mailto://user@example.com:80/bob@example.com?subject=Foo#frag',
143 'mailto:/bob@example.com?subject=Foo#frag'