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.

HostTest.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // takes a URI formatted host and validates it
  3. class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
  4. {
  5. public function test()
  6. {
  7. $this->def = new HTMLPurifier_AttrDef_URI_Host();
  8. $this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
  9. $this->assertDef('124.15.6.89'); // IPv4
  10. $this->assertDef('www.google.com'); // reg-name
  11. // more domain name tests
  12. $this->assertDef('test.');
  13. $this->assertDef('sub.test.');
  14. $this->assertDef('.test', false);
  15. $this->assertDef('ff');
  16. $this->assertDef('1f', false);
  17. $this->assertDef('-f', false);
  18. $this->assertDef('f1');
  19. $this->assertDef('f-', false);
  20. $this->assertDef('sub.ff');
  21. $this->assertDef('sub.1f', false);
  22. $this->assertDef('sub.-f', false);
  23. $this->assertDef('sub.f1');
  24. $this->assertDef('sub.f-', false);
  25. $this->assertDef('ff.top');
  26. $this->assertDef('1f.top');
  27. $this->assertDef('-f.top', false);
  28. $this->assertDef('ff.top');
  29. $this->assertDef('f1.top');
  30. $this->assertDef('f1_f2.ex.top', false);
  31. $this->assertDef('f-.top', false);
  32. $this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", false);
  33. }
  34. public function testIDNA()
  35. {
  36. if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2']) {
  37. return false;
  38. }
  39. $this->config->set('Core.EnableIDNA', true);
  40. $this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", "xn--fiq228c.com.cn");
  41. $this->assertDef("\xe2\x80\x85.com", false); // rejected
  42. }
  43. function testAllowUnderscore() {
  44. $this->config->set('Core.AllowHostnameUnderscore', true);
  45. $this->assertDef("foo_bar.example.com");
  46. $this->assertDef("foo_.example.com", false);
  47. }
  48. }
  49. // vim: et sw=4 sts=4