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?>
40--EXPECTF--
41# "K"
42
43Warning: Invalid quantity "K": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
44int(0)
45
46# "1KM"
47
48Warning: Invalid quantity "1KM", interpreting as "1M" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
49int(1048576)
50
51# "1X"
52
53Warning: Invalid quantity "1X": unknown multiplier "X", interpreting as "1" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
54int(1)
55
56# "1.0K"
57
58Warning: Invalid quantity "1.0K", interpreting as "1K" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
59int(1024)
60
61# "0X"
62
63Warning: 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
64int(0)
65
66# "0Z"
67
68Warning: Invalid prefix "0Z", interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
69int(0)
70
71# "0XK"
72
73Warning: Invalid quantity "0XK": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
74int(0)
75
76# "++"
77
78Warning: Invalid quantity "++": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
79int(0)
80
81# "-+"
82
83Warning: Invalid quantity "-+": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
84int(0)
85
86# "+ 25"
87
88Warning: Invalid quantity "+ 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
89int(0)
90
91# "- 25"
92
93Warning: Invalid quantity "- 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
94int(0)
95
96# " 123\000K"
97
98Warning: Invalid quantity " 123\x00K", interpreting as " 123K" for backwards compatibility in %s on line %d
99int(125952)
100
101# "\000 123K"
102
103Warning: Invalid quantity "\x00 123K": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d
104int(0)
105
106# " \000123K"
107
108Warning: Invalid quantity " \x00123K": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d
109int(0)
110
111# " 123\000K"
112
113Warning: Invalid quantity " 123\x00K", interpreting as " 123K" for backwards compatibility in %s on line %d
114int(125952)
115
116# " 123K\000"
117
118Warning: Invalid quantity " 123K\x00": unknown multiplier "\x00", interpreting as " 123" for backwards compatibility in %s on line %d
119int(123)
120
121# " 123\000"
122
123Warning: Invalid quantity " 123\x00": unknown multiplier "\x00", interpreting as " 123" for backwards compatibility in %s on line %d
124int(123)
125