Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / URIFilter / MakeAbsoluteTest.php
blobd509a6a16b7d6d62f8d317bcb1be39fd08365d07
1 <?php
3 require_once 'HTMLPurifier/URIFilter/MakeAbsolute.php';
4 require_once 'HTMLPurifier/URIFilterHarness.php';
6 class HTMLPurifier_URIFilter_MakeAbsoluteTest extends HTMLPurifier_URIFilterHarness
9 function setUp() {
10 parent::setUp();
11 $this->filter = new HTMLPurifier_URIFilter_MakeAbsolute();
12 $this->setBase();
15 function setBase($base = 'http://example.com/foo/bar.html?q=s#frag') {
16 $this->config->set('URI', 'Base', $base);
19 // corresponding to RFC 2396
21 function testPreserveAbsolute() {
22 $this->assertFiltering('http://example.com/foo.html');
25 function testFilterBlank() {
26 $this->assertFiltering('', 'http://example.com/foo/bar.html?q=s');
29 function testFilterEmptyPath() {
30 $this->assertFiltering('?q=s#frag', 'http://example.com/foo/bar.html?q=s#frag');
33 function testPreserveAltScheme() {
34 $this->assertFiltering('mailto:bob@example.com');
37 function testFilterIgnoreHTTPSpecialCase() {
38 $this->assertFiltering('http:/', 'http://example.com/');
41 function testFilterAbsolutePath() {
42 $this->assertFiltering('/foo.txt', 'http://example.com/foo.txt');
45 function testFilterRelativePath() {
46 $this->assertFiltering('baz.txt', 'http://example.com/foo/baz.txt');
49 function testFilterRelativePathWithInternalDot() {
50 $this->assertFiltering('./baz.txt', 'http://example.com/foo/baz.txt');
53 function testFilterRelativePathWithEndingDot() {
54 $this->assertFiltering('baz/.', 'http://example.com/foo/baz/');
57 function testFilterRelativePathDot() {
58 $this->assertFiltering('.', 'http://example.com/foo/');
61 function testFilterRelativePathWithInternalDotDot() {
62 $this->assertFiltering('../baz.txt', 'http://example.com/baz.txt');
65 function testFilterRelativePathWithEndingDotDot() {
66 $this->assertFiltering('..', 'http://example.com/');
69 function testFilterRelativePathTooManyDotDots() {
70 $this->assertFiltering('../../', 'http://example.com/');
73 function testFilterAppendingQueryAndFragment() {
74 $this->assertFiltering('/foo.php?q=s#frag', 'http://example.com/foo.php?q=s#frag');
77 // edge cases below
79 function testFilterAbsolutePathBase() {
80 $this->setBase('/foo/baz.txt');
81 $this->assertFiltering('test.php', '/foo/test.php');
84 function testFilterAbsolutePathBaseDirectory() {
85 $this->setBase('/foo/');
86 $this->assertFiltering('test.php', '/foo/test.php');
89 function testFilterAbsolutePathBaseBelow() {
90 $this->setBase('/foo/baz.txt');
91 $this->assertFiltering('../../test.php', '/test.php');
94 function testFilterRelativePathBase() {
95 $this->setBase('foo/baz.html');
96 $this->assertFiltering('foo.php', 'foo/foo.php');
99 function testFilterRelativePathBaseBelow() {
100 $this->setBase('../baz.html');
101 $this->assertFiltering('test/strike.html', '../test/strike.html');
104 function testFilterRelativePathBaseWithAbsoluteURI() {
105 $this->setBase('../baz.html');
106 $this->assertFiltering('/test/strike.html');
109 function testFilterRelativePathBaseWithDot() {
110 $this->setBase('../baz.html');
111 $this->assertFiltering('.', '../');
114 // error case
116 function testErrorNoBase() {
117 $this->setBase(null);
118 $this->expectError('URI.MakeAbsolute is being ignored due to lack of value for URI.Base configuration');
119 $this->assertFiltering('foo/bar.txt');