HostTest.php 1.5 KB

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