2006-08-12 18:58:54 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-12 19:11:21 +00:00
|
|
|
// WARNING: All the URI schemes are far to relaxed, we need to tighten
|
|
|
|
// the checks.
|
|
|
|
|
2007-08-02 01:12:27 +00:00
|
|
|
class HTMLPurifier_URISchemeTest extends HTMLPurifier_URIHarness
|
2006-08-12 18:58:54 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function assertValidation($uri, $expect_uri = true) {
|
2007-08-02 01:12:27 +00:00
|
|
|
$this->prepareURI($uri, $expect_uri);
|
2007-08-01 18:34:46 +00:00
|
|
|
// convenience hack: the scheme should be explicitly specified
|
|
|
|
$scheme = $uri->getSchemeObj($this->config, $this->context);
|
|
|
|
$result = $scheme->validate($uri, $this->config, $this->context);
|
2007-08-02 01:12:27 +00:00
|
|
|
$this->assertEitherFailOrIdentical($result, $uri, $expect_uri);
|
2007-08-01 18:34:46 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_http_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'http://example.com/?s=q#fragment'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_http_removeDefaultPort() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'http://example.com:80',
|
|
|
|
'http://example.com'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_http_removeUserInfo() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'http://bob@example.com',
|
|
|
|
'http://example.com'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_http_preserveNonDefaultPort() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'http://example.com:8080'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_https_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'https://user@example.com:443/?s=q#frag',
|
|
|
|
'https://example.com/?s=q#frag'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://user@example.com/path'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_removeDefaultPort() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://example.com:21',
|
|
|
|
'ftp://example.com'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_removeQueryString() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://example.com?s=q',
|
|
|
|
'ftp://example.com'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_preserveValidTypecode() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://example.com/file.txt;type=a'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_removeInvalidTypecode() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://example.com/file.txt;type=z',
|
|
|
|
'ftp://example.com/file.txt'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_ftp_encodeExtraSemicolons() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'ftp://example.com/too;many;semicolons=1',
|
|
|
|
'ftp://example.com/too%3Bmany%3Bsemicolons=1'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_news_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'news:gmane.science.linguistics'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_news_explicit() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'news:642@eagle.ATT.COM'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_news_removeNonPathComponents() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'news://user@example.com:80/rec.music?path=foo#frag',
|
|
|
|
'news:/rec.music#frag'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_nntp_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'nntp://news.example.com/alt.misc/42#frag'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_nntp_removalOfRedundantOrUselessComponents() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'nntp://user@news.example.com:119/alt.misc/42?s=q#frag',
|
|
|
|
'nntp://news.example.com/alt.misc/42#frag'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_mailto_regular() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'mailto:bob@example.com'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-01 18:34:46 +00:00
|
|
|
function test_mailto_removalOfRedundantOrUselessComponents() {
|
|
|
|
$this->assertValidation(
|
|
|
|
'mailto://user@example.com:80/bob@example.com?subject=Foo#frag',
|
|
|
|
'mailto:/bob@example.com?subject=Foo#frag'
|
|
|
|
);
|
2006-08-12 18:58:54 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-12 18:58:54 +00:00
|
|
|
}
|
|
|
|
|