您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

172 行
4.3KB

  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