3 class HTMLPurifier_URIFilter_MakeAbsoluteTest
extends HTMLPurifier_URIFilterHarness
8 $this->filter
= new HTMLPurifier_URIFilter_MakeAbsolute();
12 function setBase($base = 'http://example.com/foo/bar.html?q=s#frag') {
13 $this->config
->set('URI', 'Base', $base);
16 // corresponding to RFC 2396
18 function testPreserveAbsolute() {
19 $this->assertFiltering('http://example.com/foo.html');
22 function testFilterBlank() {
23 $this->assertFiltering('', 'http://example.com/foo/bar.html?q=s');
26 function testFilterEmptyPath() {
27 $this->assertFiltering('?q=s#frag', 'http://example.com/foo/bar.html?q=s#frag');
30 function testPreserveAltScheme() {
31 $this->assertFiltering('mailto:bob@example.com');
34 function testFilterIgnoreHTTPSpecialCase() {
35 $this->assertFiltering('http:/', 'http://example.com/');
38 function testFilterAbsolutePath() {
39 $this->assertFiltering('/foo.txt', 'http://example.com/foo.txt');
42 function testFilterRelativePath() {
43 $this->assertFiltering('baz.txt', 'http://example.com/foo/baz.txt');
46 function testFilterRelativePathWithInternalDot() {
47 $this->assertFiltering('./baz.txt', 'http://example.com/foo/baz.txt');
50 function testFilterRelativePathWithEndingDot() {
51 $this->assertFiltering('baz/.', 'http://example.com/foo/baz/');
54 function testFilterRelativePathDot() {
55 $this->assertFiltering('.', 'http://example.com/foo/');
58 function testFilterRelativePathMultiDot() {
59 $this->assertFiltering('././foo/./bar/.././baz', 'http://example.com/foo/foo/baz');
62 function testFilterAbsolutePathWithDot() {
63 $this->assertFiltering('/./foo', 'http://example.com/foo');
66 function testFilterAbsolutePathWithMultiDot() {
67 $this->assertFiltering('/./foo/../bar/.', 'http://example.com/bar/');
70 function testFilterRelativePathWithInternalDotDot() {
71 $this->assertFiltering('../baz.txt', 'http://example.com/baz.txt');
74 function testFilterRelativePathWithEndingDotDot() {
75 $this->assertFiltering('..', 'http://example.com/');
78 function testFilterRelativePathTooManyDotDots() {
79 $this->assertFiltering('../../', 'http://example.com/');
82 function testFilterAppendingQueryAndFragment() {
83 $this->assertFiltering('/foo.php?q=s#frag', 'http://example.com/foo.php?q=s#frag');
88 function testFilterAbsolutePathBase() {
89 $this->setBase('/foo/baz.txt');
90 $this->assertFiltering('test.php', '/foo/test.php');
93 function testFilterAbsolutePathBaseDirectory() {
94 $this->setBase('/foo/');
95 $this->assertFiltering('test.php', '/foo/test.php');
98 function testFilterAbsolutePathBaseBelow() {
99 $this->setBase('/foo/baz.txt');
100 $this->assertFiltering('../../test.php', '/test.php');
103 function testFilterRelativePathBase() {
104 $this->setBase('foo/baz.html');
105 $this->assertFiltering('foo.php', 'foo/foo.php');
108 function testFilterRelativePathBaseBelow() {
109 $this->setBase('../baz.html');
110 $this->assertFiltering('test/strike.html', '../test/strike.html');
113 function testFilterRelativePathBaseWithAbsoluteURI() {
114 $this->setBase('../baz.html');
115 $this->assertFiltering('/test/strike.html');
118 function testFilterRelativePathBaseWithDot() {
119 $this->setBase('../baz.html');
120 $this->assertFiltering('.', '../');
123 function testRemoveJavaScriptWithEmbeddedLink() {
125 $this->setBase('http://www.example.com/');
126 $this->assertFiltering('javascript: window.location = \'http://www.example.com\';', false);
131 function testFilterDomainWithNoSlash() {
132 $this->setBase('http://example.com');
133 $this->assertFiltering('foo', 'http://example.com/foo');
138 function testErrorNoBase() {
139 $this->setBase(null);
140 $this->expectError('URI.MakeAbsolute is being ignored due to lack of value for URI.Base configuration');
141 $this->assertFiltering('foo/bar.txt');