xref: /php-src/ext/filter/tests/bug77221.phpt (revision 218a93b8)
1--TEST--
2Bug #77221 (Request IP address filter flag to exclude non-global IP addresses)
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7
8$non_global_ranges = [];
9$non_global_ranges['0.0.0.0/8'] = ['0.0.0.0', '0.255.255.255'];
10$non_global_ranges['10.0.0.0/8'] = ['10.0.0.0', '10.255.255.255'];
11$non_global_ranges['100.64.0.0/10'] = ['100.64.0.0', '100.127.255.255'];
12$non_global_ranges['127.0.0.0/8'] = ['127.0.0.0', '127.255.255.255'];
13$non_global_ranges['169.254.0.0/16'] = ['169.254.0.0', '169.254.255.255'];
14$non_global_ranges['172.16.0.0/12'] = ['172.16.0.0', '172.31.255.255'];
15$non_global_ranges['192.0.0.0/24'] = ['192.0.0.0', '192.0.0.255'];
16$non_global_ranges['192.0.2.0/24'] = ['192.0.2.0', '192.0.2.255'];
17$non_global_ranges['192.168.0.0/16'] = ['192.168.0.0', '192.168.255.255'];
18$non_global_ranges['198.18.0.0/15'] = ['198.18.0.0', '198.19.255.255'];
19$non_global_ranges['198.51.100.0/24'] = ['198.51.100.0', '198.51.100.255'];
20$non_global_ranges['203.0.113.0/24'] = ['203.0.113.0', '203.0.113.255'];
21$non_global_ranges['240.0.0.0/4'] = ['240.0.0.0', '255.255.255.255'];
22
23$non_global_ranges['::/128'] = ['::0', '::'];
24$non_global_ranges['::1/128'] = ['0000:0000:0000:0000:0000:0000:0000:1', '0:0:0:0:0:0:0:1'];
25$non_global_ranges['::ffff:0:0/96'] = ['::ffff:0:0', '::ffff:ffff:ffff'];
26$non_global_ranges['100::/64'] = ['0100::', '100::ffff:ffff:ffff:ffff'];
27$non_global_ranges['2001::/23'] = ['2001::', '2001:01ff:ffff:ffff:ffff:ffff:ffff:ffff'];
28$non_global_ranges['2001:2::/48'] = ['2001:2::', '2001:2:0:ffff:ffff:ffff:ffff:ffff'];
29$non_global_ranges['2001:db8::/32'] = ['2001:db8::', '2001:db8:ffff:ffff:ffff:ffff:ffff:ffff'];
30$non_global_ranges['2001:10::/28'] = ['2001:10::', '2001:1f:ffff:ffff:ffff:ffff:ffff:ffff'];
31$non_global_ranges['fc00::/7'] = ['fc00::', 'fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'];
32$non_global_ranges['fe80::/10'] = ['fe80::', 'febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff'];
33
34
35foreach ($non_global_ranges as $key => $range) {
36    list($min, $max) = $range;
37    var_dump($key);
38    var_dump(filter_var($min, FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
39    var_dump(filter_var($max, FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
40}
41
42var_dump(filter_var('185.85.0.29', FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
43var_dump(filter_var('64:ff9b::', FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
44var_dump(filter_var('64:ff9b::ffff', FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
45
46?>
47--EXPECT--
48string(9) "0.0.0.0/8"
49bool(false)
50bool(false)
51string(10) "10.0.0.0/8"
52bool(false)
53bool(false)
54string(13) "100.64.0.0/10"
55bool(false)
56bool(false)
57string(11) "127.0.0.0/8"
58bool(false)
59bool(false)
60string(14) "169.254.0.0/16"
61bool(false)
62bool(false)
63string(13) "172.16.0.0/12"
64bool(false)
65bool(false)
66string(12) "192.0.0.0/24"
67bool(false)
68bool(false)
69string(12) "192.0.2.0/24"
70bool(false)
71bool(false)
72string(14) "192.168.0.0/16"
73bool(false)
74bool(false)
75string(13) "198.18.0.0/15"
76bool(false)
77bool(false)
78string(15) "198.51.100.0/24"
79bool(false)
80bool(false)
81string(14) "203.0.113.0/24"
82bool(false)
83bool(false)
84string(11) "240.0.0.0/4"
85bool(false)
86bool(false)
87string(6) "::/128"
88bool(false)
89bool(false)
90string(7) "::1/128"
91bool(false)
92bool(false)
93string(13) "::ffff:0:0/96"
94bool(false)
95bool(false)
96string(8) "100::/64"
97bool(false)
98bool(false)
99string(9) "2001::/23"
100bool(false)
101bool(false)
102string(11) "2001:2::/48"
103bool(false)
104bool(false)
105string(13) "2001:db8::/32"
106bool(false)
107bool(false)
108string(12) "2001:10::/28"
109bool(false)
110bool(false)
111string(8) "fc00::/7"
112bool(false)
113bool(false)
114string(9) "fe80::/10"
115bool(false)
116bool(false)
117string(11) "185.85.0.29"
118string(9) "64:ff9b::"
119string(13) "64:ff9b::ffff"
120