Accept leading digits in hostnames as per RFC 1123.
[htmlpurifier.git] / tests / HTMLPurifier / AttrDef / URI / HostTest.php
blob1f20a7482952ec72cd7868020c428bca88141a63
1 <?php
3 // takes a URI formatted host and validates it
6 class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
9 public function test()
11 $this->def = new HTMLPurifier_AttrDef_URI_Host();
13 $this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
14 $this->assertDef('124.15.6.89'); // IPv4
15 $this->assertDef('www.google.com'); // reg-name
17 // more domain name tests
18 $this->assertDef('test.');
19 $this->assertDef('sub.test.');
20 $this->assertDef('.test', false);
21 $this->assertDef('ff');
22 $this->assertDef('1f'); // per RFC 1123
23 // See also http://serverfault.com/questions/638260/is-it-valid-for-a-hostname-to-start-with-a-digit
24 $this->assertDef('-f', false);
25 $this->assertDef('f1');
26 $this->assertDef('f-', false);
27 $this->assertDef('sub.ff');
28 $this->assertDef('sub.1f'); // per RFC 1123
29 $this->assertDef('sub.-f', false);
30 $this->assertDef('sub.f1');
31 $this->assertDef('sub.f-', false);
32 $this->assertDef('ff.top');
33 $this->assertDef('1f.top');
34 $this->assertDef('-f.top', false);
35 $this->assertDef('ff.top');
36 $this->assertDef('f1.top');
37 $this->assertDef('f1_f2.ex.top', false);
38 $this->assertDef('f-.top', false);
39 $this->assertDef('1a');
41 $this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", false);
45 public function testIDNA()
47 if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2'] && !function_exists("idn_to_ascii")) {
48 return false;
50 $this->config->set('Core.EnableIDNA', true);
51 $this->assertDef("\xE4\xB8\xAD\xE6\x96\x87.com.cn", "xn--fiq228c.com.cn");
52 $this->assertDef("\xe2\x80\x85.com", false); // rejected
55 function testAllowUnderscore() {
56 $this->config->set('Core.AllowHostnameUnderscore', true);
57 $this->assertDef("foo_bar.example.com");
58 $this->assertDef("foo_.example.com", false);
63 // vim: et sw=4 sts=4