1--TEST--
2Bug #71745 FILTER_FLAG_NO_RES_RANGE does not cover whole 127.0.0.0/8 range
3--SKIPIF--
4<?php if (!extension_loaded('filter')) die('skip filter extension not loaded'); ?>
5--FILE--
6<?php
7//https://tools.ietf.org/html/rfc6890#section-2.1
8
9$privateRanges = array();
10// 10.0.0.0/8
11$privateRanges['10.0.0.0/8'] = array('10.0.0.0', '10.255.255.255');
12
13// 169.254.0.0/16
14$privateRanges['168.254.0.0/16'] = array('169.254.0.0', '169.254.255.255');
15
16// 172.16.0.0/12
17$privateRanges['172.16.0.0/12'] = array('172.16.0.0', '172.31.0.0');
18
19// 192.168.0.0/16
20$privateRanges['192.168.0.0/16'] = array('192.168.0.0', '192.168.255.255');
21
22foreach ($privateRanges as $key => $range) {
23    list($min, $max) = $range;
24    var_dump($key);
25    var_dump(filter_var($min, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE));
26    var_dump(filter_var($max, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE));
27}
28
29$reservedRanges = array();
30
31// 0.0.0.0/8
32$reservedRanges['0.0.0.0/8'] = array('0.0.0.0', '0.255.255.255');
33
34// 10.0.0.0/8
35$reservedRanges['10.0.0.0/8'] = array('10.0.0.0', '10.255.255.255');
36
37// 100.64.0.0/10
38$reservedRanges['10.64.0.0/10'] = array('100.64.0.0', '100.127.255.255');
39
40// 127.0.0.0/8
41$reservedRanges['127.0.0.0/8'] = array('127.0.0.0', '127.255.255.255');
42
43// 169.254.0.0/16
44$reservedRanges['169.254.0.0/16'] = array('169.254.0.0', '169.254.255.255');
45
46// 172.16.0.0/12
47$reservedRanges['172.16.0.0/12'] = array('172.16.0.0', '172.31.0.0');
48
49// 192.0.0.0/24
50$reservedRanges['192.0.0.0/24'] = array('192.0.0.0', '192.0.0.255');
51
52// 192.0.0.0/29
53$reservedRanges['192.0.0.0/29'] = array('192.0.0.0', '192.0.0.7');
54
55// 192.0.2.0/24
56$reservedRanges['192.0.2.0/24'] = array('192.0.2.0', '192.0.2.255');
57
58// 198.18.0.0/15
59$reservedRanges['198.18.0.0/15'] = array('198.18.0.0', '198.19.255.255');
60
61// 198.51.100.0/24
62$reservedRanges['198.51.100.0/24'] = array('198.51.100.0', '198.51.100.255');
63
64// 192.88.99.0/24
65$reservedRanges['192.88.99.0/24'] = array('192.88.99.0', '192.88.99.255');
66
67// 192.168.0.0/16
68$reservedRanges['192.168.0.0/16'] = array('192.168.0.0', '192.168.255.255');
69
70// 203.0.113.0/24
71$reservedRanges['203.0.113.0/24'] = array('203.0.113.0', '203.0.113.255');
72
73// 240.0.0.0/4 + 255.255.255.255/32
74$reservedRanges['240.0.0.0/4'] = array('224.0.0.0', '255.255.255.255');
75
76foreach ($reservedRanges as $key => $range) {
77    list($min, $max) = $range;
78    var_dump($key);
79    var_dump(filter_var($min, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE));
80    var_dump(filter_var($max, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE));
81}
82
83?>
84--EXPECT--
85string(10) "10.0.0.0/8"
86bool(false)
87bool(false)
88string(14) "168.254.0.0/16"
89string(11) "169.254.0.0"
90string(15) "169.254.255.255"
91string(13) "172.16.0.0/12"
92bool(false)
93bool(false)
94string(14) "192.168.0.0/16"
95bool(false)
96bool(false)
97string(9) "0.0.0.0/8"
98bool(false)
99bool(false)
100string(10) "10.0.0.0/8"
101string(8) "10.0.0.0"
102string(14) "10.255.255.255"
103string(12) "10.64.0.0/10"
104string(10) "100.64.0.0"
105string(15) "100.127.255.255"
106string(11) "127.0.0.0/8"
107bool(false)
108bool(false)
109string(14) "169.254.0.0/16"
110bool(false)
111bool(false)
112string(13) "172.16.0.0/12"
113string(10) "172.16.0.0"
114string(10) "172.31.0.0"
115string(12) "192.0.0.0/24"
116string(9) "192.0.0.0"
117string(11) "192.0.0.255"
118string(12) "192.0.0.0/29"
119string(9) "192.0.0.0"
120string(9) "192.0.0.7"
121string(12) "192.0.2.0/24"
122string(9) "192.0.2.0"
123string(11) "192.0.2.255"
124string(13) "198.18.0.0/15"
125string(10) "198.18.0.0"
126string(14) "198.19.255.255"
127string(15) "198.51.100.0/24"
128string(12) "198.51.100.0"
129string(14) "198.51.100.255"
130string(14) "192.88.99.0/24"
131string(11) "192.88.99.0"
132string(13) "192.88.99.255"
133string(14) "192.168.0.0/16"
134string(11) "192.168.0.0"
135string(15) "192.168.255.255"
136string(14) "203.0.113.0/24"
137string(11) "203.0.113.0"
138string(13) "203.0.113.255"
139string(11) "240.0.0.0/4"
140string(9) "224.0.0.0"
141bool(false)
142