You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

URIParserTest.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. class HTMLPurifier_URIParserTest extends HTMLPurifier_Harness
  3. {
  4. protected function assertParsing(
  5. $uri, $scheme, $userinfo, $host, $port, $path, $query, $fragment, $config = null, $context = null
  6. ) {
  7. $this->prepareCommon($config, $context);
  8. $parser = new HTMLPurifier_URIParser();
  9. $result = $parser->parse($uri, $config, $context);
  10. $expect = new HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
  11. $this->assertEqual($result, $expect);
  12. }
  13. public function testPercentNormalization()
  14. {
  15. $this->assertParsing(
  16. '%G',
  17. null, null, null, null, '%25G', null, null
  18. );
  19. }
  20. public function testRegular()
  21. {
  22. $this->assertParsing(
  23. 'http://www.example.com/webhp?q=foo#result2',
  24. 'http', null, 'www.example.com', null, '/webhp', 'q=foo', 'result2'
  25. );
  26. }
  27. public function testPortAndUsername()
  28. {
  29. $this->assertParsing(
  30. 'http://user@authority.part:80/now/the/path?query#fragment',
  31. 'http', 'user', 'authority.part', 80, '/now/the/path', 'query', 'fragment'
  32. );
  33. }
  34. public function testPercentEncoding()
  35. {
  36. $this->assertParsing(
  37. 'http://en.wikipedia.org/wiki/Clich%C3%A9',
  38. 'http', null, 'en.wikipedia.org', null, '/wiki/Clich%C3%A9', null, null
  39. );
  40. }
  41. public function testEmptyQuery()
  42. {
  43. $this->assertParsing(
  44. 'http://www.example.com/?#',
  45. 'http', null, 'www.example.com', null, '/', '', null
  46. );
  47. }
  48. public function testEmptyPath()
  49. {
  50. $this->assertParsing(
  51. 'http://www.example.com',
  52. 'http', null, 'www.example.com', null, '', null, null
  53. );
  54. }
  55. public function testOpaqueURI()
  56. {
  57. $this->assertParsing(
  58. 'mailto:bob@example.com',
  59. 'mailto', null, null, null, 'bob@example.com', null, null
  60. );
  61. }
  62. public function testIPv4Address()
  63. {
  64. $this->assertParsing(
  65. 'http://192.0.34.166/',
  66. 'http', null, '192.0.34.166', null, '/', null, null
  67. );
  68. }
  69. public function testFakeIPv4Address()
  70. {
  71. $this->assertParsing(
  72. 'http://333.123.32.123/',
  73. 'http', null, '333.123.32.123', null, '/', null, null
  74. );
  75. }
  76. public function testIPv6Address()
  77. {
  78. $this->assertParsing(
  79. 'http://[2001:db8::7]/c=GB?objectClass?one',
  80. 'http', null, '[2001:db8::7]', null, '/c=GB', 'objectClass?one', null
  81. );
  82. }
  83. public function testInternationalizedDomainName()
  84. {
  85. $this->assertParsing(
  86. "http://t\xC5\xABdali\xC5\x86.lv",
  87. 'http', null, "t\xC5\xABdali\xC5\x86.lv", null, '', null, null
  88. );
  89. }
  90. public function testInvalidPort()
  91. {
  92. $this->assertParsing(
  93. 'http://example.com:foobar',
  94. 'http', null, 'example.com', null, '', null, null
  95. );
  96. }
  97. public function testPathAbsolute()
  98. {
  99. $this->assertParsing(
  100. 'http:/this/is/path',
  101. 'http', null, null, null, '/this/is/path', null, null
  102. );
  103. }
  104. public function testPathRootless()
  105. {
  106. // this should not be used but is allowed
  107. $this->assertParsing(
  108. 'http:this/is/path',
  109. 'http', null, null, null, 'this/is/path', null, null
  110. );
  111. }
  112. public function testPathEmpty()
  113. {
  114. $this->assertParsing(
  115. 'http:',
  116. 'http', null, null, null, '', null, null
  117. );
  118. }
  119. public function testRelativeURI()
  120. {
  121. $this->assertParsing(
  122. '/a/b',
  123. null, null, null, null, '/a/b', null, null
  124. );
  125. }
  126. public function testMalformedTag()
  127. {
  128. $this->assertParsing(
  129. 'http://www.example.com/>',
  130. 'http', null, 'www.example.com', null, '/', null, null
  131. );
  132. }
  133. public function testEmpty()
  134. {
  135. $this->assertParsing(
  136. '',
  137. null, null, null, null, '', null, null
  138. );
  139. }
  140. public function testEmbeddedColon()
  141. {
  142. $this->assertParsing(
  143. '{:test:}',
  144. null, null, null, null, '{:test:}', null, null
  145. );
  146. }
  147. }
  148. // vim: et sw=4 sts=4