xref: /PHP-7.0/ext/filter/tests/030.phpt (revision c3557ba3)
1--TEST--
2filter_var() and IPv6
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7$ipv6_test = array(
8	"::127.0.0.1"					=> true,
9	"FF01::101:127.0.1" 			=> false,
10	"FF01:0:0:0:101:127.0.1.1"		=> false,
11	"FF01:0:0:0:237:101:127.0.1.1"	=> true,
12	"FF01::101"						=> true,
13	"A1080::8:800:200C:417A"		=> false,
14	"1080::8:Z00:200C:417A"			=> false,
15	"FF01::101::1"					=> false,
16	"1080::8:800:200C:417A"			=> true,
17	"1080:0:0:0:8:800:200C:417A"	=> true,
18	"2001:ec8:1:1:1:1:1:1"			=> true,
19	"ffff::FFFF:129.144.52.38"		=> true,
20	"::ffff:1.2.3.4"				=> true,
21	"0:0:0:0:0:FFFF:129.144.52.38"	=> true,
22	"0:0:0:0:0:0:13.1.68.3"			=> true,
23    "0:0:0:0:0:0:0:13.1.68.3"		=> false,
24	"::13.1.68.3"					=> true,
25    "::FFFF:129.144.52.38"			=> true,
26
27    "1:2:3:4:5:6::129.144.52.38"	=> false,
28    "::1:2:3:4:5:6:129.144.52.38"	=> false,
29    "1:2:3::4:5:6:129.144.52.38"	=> false,
30
31    "1:2:3:4::5:6:7:8"				=> false,
32    "::1:2:3:4:5:6:7"				=> true,
33    "::1:2:3:4:5:6:7:8"				=> false,
34    "1:2:3:4:5:6:7::"				=> true,
35    "1:2:3:4:5:6:7:8::"				=> false,
36    "1:2:3:4:5:6:7::8"				=> false,
37
38    "1:2:3:4:5:6:7:8g"				=> false,
39    "1:2:3:4:5:6:7:g"				=> false,
40    "1:2:3:4:5g:6:7:8"				=> false,
41
42    'a:b:c:d:e::1.2.3.4'			=> true,
43    '::0:a:b:c:d:e:f'				=> true,
44    '0:a:b:c:d:e:f::'				=> true,
45    ':::1.2.3.4'					=> false,
46    '8:::1.2.3.4'					=> false,
47    '::01.02.03.04'					=> false,
48    '::1.00.3.4'					=> false,
49    '0:0:0:255.255.255.255'			=> false,
50    '0:0:0::255.255.255.255'		=> true,
51);
52foreach ($ipv6_test as $ip => $exp) {
53	$out = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
54	$out = (int) ($out === false ? 0 : 1);
55	if ($exp != $out) {
56		echo "$ip failed (expected ", $exp?"true":"false", ", got ",
57            $out?"true":"false", ")\n";
58	}
59}
60
61echo "Ok\n";
62?>
63--EXPECT--
64Ok
65