3 class HTMLPurifier_URIFilter_MakeAbsoluteTest
extends HTMLPurifier_URIFilterHarness
6 public function setUp()
9 $this->filter
= new HTMLPurifier_URIFilter_MakeAbsolute();
13 public function setBase($base = 'http://example.com/foo/bar.html?q=s#frag')
15 $this->config
->set('URI.Base', $base);
18 // corresponding to RFC 2396
20 public function testPreserveAbsolute()
22 $this->assertFiltering('http://example.com/foo.html');
25 public function testFilterBlank()
27 $this->assertFiltering('', 'http://example.com/foo/bar.html?q=s');
30 public function testFilterEmptyPath()
32 $this->assertFiltering('?q=s#frag', 'http://example.com/foo/bar.html?q=s#frag');
35 public function testPreserveAltScheme()
37 $this->assertFiltering('mailto:bob@example.com');
40 public function testPreserveAltSchemeWithTel()
42 $this->assertFiltering('tel:+15555555555');
45 public function testFilterIgnoreHTTPSpecialCase()
47 $this->assertFiltering('http:/', 'http://example.com/');
50 public function testFilterAbsolutePath()
52 $this->assertFiltering('/foo.txt', 'http://example.com/foo.txt');
55 public function testFilterRelativePath()
57 $this->assertFiltering('baz.txt', 'http://example.com/foo/baz.txt');
60 public function testFilterRelativePathWithInternalDot()
62 $this->assertFiltering('./baz.txt', 'http://example.com/foo/baz.txt');
65 public function testFilterRelativePathWithEndingDot()
67 $this->assertFiltering('baz/.', 'http://example.com/foo/baz/');
70 public function testFilterRelativePathDot()
72 $this->assertFiltering('.', 'http://example.com/foo/');
75 public function testFilterRelativePathMultiDot()
77 $this->assertFiltering('././foo/./bar/.././baz', 'http://example.com/foo/foo/baz');
80 public function testFilterAbsolutePathWithDot()
82 $this->assertFiltering('/./foo', 'http://example.com/foo');
85 public function testFilterAbsolutePathWithMultiDot()
87 $this->assertFiltering('/./foo/../bar/.', 'http://example.com/bar/');
90 public function testFilterRelativePathWithInternalDotDot()
92 $this->assertFiltering('../baz.txt', 'http://example.com/baz.txt');
95 public function testFilterRelativePathWithEndingDotDot()
97 $this->assertFiltering('..', 'http://example.com/');
100 public function testFilterRelativePathTooManyDotDots()
102 $this->assertFiltering('../../', 'http://example.com/');
105 public function testFilterAppendingQueryAndFragment()
107 $this->assertFiltering('/foo.php?q=s#frag', 'http://example.com/foo.php?q=s#frag');
112 public function testFilterAbsolutePathBase()
114 $this->setBase('/foo/baz.txt');
115 $this->assertFiltering('test.php', '/foo/test.php');
118 public function testFilterAbsolutePathBaseDirectory()
120 $this->setBase('/foo/');
121 $this->assertFiltering('test.php', '/foo/test.php');
124 public function testFilterAbsolutePathBaseBelow()
126 $this->setBase('/foo/baz.txt');
127 $this->assertFiltering('../../test.php', '/test.php');
130 public function testFilterRelativePathBase()
132 $this->setBase('foo/baz.html');
133 $this->assertFiltering('foo.php', 'foo/foo.php');
136 public function testFilterRelativePathBaseBelow()
138 $this->setBase('../baz.html');
139 $this->assertFiltering('test/strike.html', '../test/strike.html');
142 public function testFilterRelativePathBaseWithAbsoluteURI()
144 $this->setBase('../baz.html');
145 $this->assertFiltering('/test/strike.html');
148 public function testFilterRelativePathBaseWithDot()
150 $this->setBase('../baz.html');
151 $this->assertFiltering('.', '../');
154 public function testRemoveJavaScriptWithEmbeddedLink()
157 $this->setBase('http://www.example.com/');
158 $this->assertFiltering('javascript: window.location = \'http://www.example.com\';', false);
163 public function testFilterDomainWithNoSlash()
165 $this->setBase('http://example.com');
166 $this->assertFiltering('foo', 'http://example.com/foo');
171 public function testErrorNoBase()
173 $this->setBase(null);
174 $this->expectError('URI.MakeAbsolute is being ignored due to lack of value for URI.Base configuration');
175 $this->assertFiltering('foo/bar.txt');
180 // vim: et sw=4 sts=4