1--TEST--
2Test parsing of quantities: errors
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8// This test checks invalid formats do throw warnings.
9
10$tests = [
11    'K',     # No digits
12    '1KM',   # Multiple multipliers.
13    '1X',    # Unknown multiplier.
14    '1.0K',  # Non integral digits.
15
16    '0X',    # Valid prefix with no value
17    '0Z',    # Invalid prefix
18    '0XK',   # Valid prefix with no value and multiplier
19
20    '++',
21    '-+',
22    '+ 25',
23    '- 25',
24
25    # Null bytes
26    " 123\x00K",
27    "\x00 123K",
28    " \x00123K",
29    " 123\x00K",
30    " 123K\x00",
31    " 123\x00",
32];
33
34foreach ($tests as $setting) {
35    printf("# \"%s\"\n", addcslashes($setting, "\0..\37!@\177..\377"));
36    var_dump(zend_test_zend_ini_parse_quantity($setting));
37    print "\n";
38}
39--EXPECTF--
40# "K"
41
42Warning: Invalid quantity "K": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
43int(0)
44
45# "1KM"
46
47Warning: Invalid quantity "1KM", interpreting as "1M" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
48int(1048576)
49
50# "1X"
51
52Warning: Invalid quantity "1X": unknown multiplier "X", interpreting as "1" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
53int(1)
54
55# "1.0K"
56
57Warning: Invalid quantity "1.0K", interpreting as "1K" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
58int(1024)
59
60# "0X"
61
62Warning: Invalid quantity "0X": no digits after base prefix, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
63int(0)
64
65# "0Z"
66
67Warning: Invalid prefix "0Z", interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
68int(0)
69
70# "0XK"
71
72Warning: Invalid quantity "0XK": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
73int(0)
74
75# "++"
76
77Warning: Invalid quantity "++": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
78int(0)
79
80# "-+"
81
82Warning: Invalid quantity "-+": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
83int(0)
84
85# "+ 25"
86
87Warning: Invalid quantity "+ 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
88int(0)
89
90# "- 25"
91
92Warning: Invalid quantity "- 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
93int(0)
94
95# " 123\000K"
96
97Warning: Invalid quantity " 123\x00K", interpreting as " 123K" for backwards compatibility in %s on line %d
98int(125952)
99
100# "\000 123K"
101
102Warning: Invalid quantity "\x00 123K": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d
103int(0)
104
105# " \000123K"
106
107Warning: Invalid quantity " \x00123K": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d
108int(0)
109
110# " 123\000K"
111
112Warning: Invalid quantity " 123\x00K", interpreting as " 123K" for backwards compatibility in %s on line %d
113int(125952)
114
115# " 123K\000"
116
117Warning: Invalid quantity " 123K\x00": unknown multiplier "\x00", interpreting as " 123" for backwards compatibility in %s on line %d
118int(123)
119
120# " 123\000"
121
122Warning: Invalid quantity " 123\x00": unknown multiplier "\x00", interpreting as " 123" for backwards compatibility in %s on line %d
123int(123)
124