Make URI parsing algorithm more strict.
[htmlpurifier.git] / tests / HTMLPurifier / URIParserTest.php
blobcbca196ce62012da902a59f09aaf8bbf1d3ba853
1 <?php
3 class HTMLPurifier_URIParserTest extends HTMLPurifier_Harness
6 protected function assertParsing(
7 $uri, $scheme, $userinfo, $host, $port, $path, $query, $fragment, $config = null, $context = null
8 ) {
9 $this->prepareCommon($config, $context);
10 $parser = new HTMLPurifier_URIParser();
11 $result = $parser->parse($uri, $config, $context);
12 $expect = new HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
13 $this->assertEqual($result, $expect);
16 function testPercentNormalization() {
17 $this->assertParsing(
18 '%G',
19 null, null, null, null, '%25G', null, null
23 function testRegular() {
24 $this->assertParsing(
25 'http://www.example.com/webhp?q=foo#result2',
26 'http', null, 'www.example.com', null, '/webhp', 'q=foo', 'result2'
30 function testPortAndUsername() {
31 $this->assertParsing(
32 'http://user@authority.part:80/now/the/path?query#fragment',
33 'http', 'user', 'authority.part', 80, '/now/the/path', 'query', 'fragment'
37 function testPercentEncoding() {
38 $this->assertParsing(
39 'http://en.wikipedia.org/wiki/Clich%C3%A9',
40 'http', null, 'en.wikipedia.org', null, '/wiki/Clich%C3%A9', null, null
44 function testEmptyQuery() {
45 $this->assertParsing(
46 'http://www.example.com/?#',
47 'http', null, 'www.example.com', null, '/', '', null
51 function testEmptyPath() {
52 $this->assertParsing(
53 'http://www.example.com',
54 'http', null, 'www.example.com', null, '', null, null
58 function testOpaqueURI() {
59 $this->assertParsing(
60 'mailto:bob@example.com',
61 'mailto', null, null, null, 'bob@example.com', null, null
65 function testIPv4Address() {
66 $this->assertParsing(
67 'http://192.0.34.166/',
68 'http', null, '192.0.34.166', null, '/', null, null
72 function testFakeIPv4Address() {
73 $this->assertParsing(
74 'http://333.123.32.123/',
75 'http', null, '333.123.32.123', null, '/', null, null
79 function testIPv6Address() {
80 $this->assertParsing(
81 'http://[2001:db8::7]/c=GB?objectClass?one',
82 'http', null, '[2001:db8::7]', null, '/c=GB', 'objectClass?one', null
86 function testInternationalizedDomainName() {
87 $this->assertParsing(
88 "http://t\xC5\xABdali\xC5\x86.lv",
89 'http', null, "t\xC5\xABdali\xC5\x86.lv", null, '', null, null
93 function testInvalidPort() {
94 $this->assertParsing(
95 'http://example.com:foobar',
96 'http', null, 'example.com', null, '', null, null
100 function testPathAbsolute() {
101 $this->assertParsing(
102 'http:/this/is/path',
103 'http', null, null, null, '/this/is/path', null, null
107 function testPathRootless() {
108 // this should not be used but is allowed
109 $this->assertParsing(
110 'http:this/is/path',
111 'http', null, null, null, 'this/is/path', null, null
115 function testPathEmpty() {
116 $this->assertParsing(
117 'http:',
118 'http', null, null, null, '', null, null
122 function testRelativeURI() {
123 $this->assertParsing(
124 '/a/b',
125 null, null, null, null, '/a/b', null, null
129 function testMalformedTag() {
130 $this->assertParsing(
131 'http://www.example.com/>',
132 'http', null, 'www.example.com', null, '/', null, null
136 function testEmpty() {
137 $this->assertParsing(
139 null, null, null, null, '', null, null
143 function testEmbeddedColon() {
144 $this->assertParsing(
145 '{:test:}',
146 null, null, null, null, '{:test:}', null, null
152 // vim: et sw=4 sts=4