xref: /PHP-7.2/ext/json/tests/fail001.phpt (revision f1d7e3ca)
1--TEST--
2JSON (http://www.crockford.com/JSON/JSON_checker/test/fail*.json)
3--SKIPIF--
4<?php
5  if (!extension_loaded('json')) die('skip');
6?>
7--FILE--
8<?php
9
10$tests = array(
11	'"A JSON payload should be an object or array, not a string."',
12	'["Unclosed array"',
13	'{unquoted_key: "keys must be quoted}',
14	'["extra comma",]',
15	'["double extra comma",,]',
16	'[   , "<-- missing value"]',
17	'["Comma after the close"],',
18	'["Extra close"]]',
19	'{"Extra comma": true,}',
20	'{"Extra value after close": true} "misplaced quoted value"',
21	'{"Illegal expression": 1 + 2}',
22	'{"Illegal invocation": alert()}',
23	'{"Numbers cannot have leading zeroes": 013}',
24	'{"Numbers cannot be hex": 0x14}',
25	'["Illegal backslash escape: \\x15"]',
26	'["Illegal backslash escape: \\\'"]',
27	'["Illegal backslash escape: \\017"]',
28	'[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]',
29	'{"Missing colon" null}',
30	'{"Double colon":: null}',
31	'{"Comma instead of colon", null}',
32	'["Colon instead of comma": false]',
33	'["Bad value", truth]',
34	"['single quote']"
35);
36
37foreach ($tests as $test) {
38	echo 'Testing: ' . $test . "\n";
39	echo "AS OBJECT\n";
40	var_dump(json_decode($test));
41	echo "AS ARRAY\n";
42	var_dump(json_decode($test, true));
43}
44
45?>
46--EXPECT--
47Testing: "A JSON payload should be an object or array, not a string."
48AS OBJECT
49string(58) "A JSON payload should be an object or array, not a string."
50AS ARRAY
51string(58) "A JSON payload should be an object or array, not a string."
52Testing: ["Unclosed array"
53AS OBJECT
54NULL
55AS ARRAY
56NULL
57Testing: {unquoted_key: "keys must be quoted}
58AS OBJECT
59NULL
60AS ARRAY
61NULL
62Testing: ["extra comma",]
63AS OBJECT
64NULL
65AS ARRAY
66NULL
67Testing: ["double extra comma",,]
68AS OBJECT
69NULL
70AS ARRAY
71NULL
72Testing: [   , "<-- missing value"]
73AS OBJECT
74NULL
75AS ARRAY
76NULL
77Testing: ["Comma after the close"],
78AS OBJECT
79NULL
80AS ARRAY
81NULL
82Testing: ["Extra close"]]
83AS OBJECT
84NULL
85AS ARRAY
86NULL
87Testing: {"Extra comma": true,}
88AS OBJECT
89NULL
90AS ARRAY
91NULL
92Testing: {"Extra value after close": true} "misplaced quoted value"
93AS OBJECT
94NULL
95AS ARRAY
96NULL
97Testing: {"Illegal expression": 1 + 2}
98AS OBJECT
99NULL
100AS ARRAY
101NULL
102Testing: {"Illegal invocation": alert()}
103AS OBJECT
104NULL
105AS ARRAY
106NULL
107Testing: {"Numbers cannot have leading zeroes": 013}
108AS OBJECT
109NULL
110AS ARRAY
111NULL
112Testing: {"Numbers cannot be hex": 0x14}
113AS OBJECT
114NULL
115AS ARRAY
116NULL
117Testing: ["Illegal backslash escape: \x15"]
118AS OBJECT
119NULL
120AS ARRAY
121NULL
122Testing: ["Illegal backslash escape: \'"]
123AS OBJECT
124NULL
125AS ARRAY
126NULL
127Testing: ["Illegal backslash escape: \017"]
128AS OBJECT
129NULL
130AS ARRAY
131NULL
132Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
133AS OBJECT
134NULL
135AS ARRAY
136NULL
137Testing: {"Missing colon" null}
138AS OBJECT
139NULL
140AS ARRAY
141NULL
142Testing: {"Double colon":: null}
143AS OBJECT
144NULL
145AS ARRAY
146NULL
147Testing: {"Comma instead of colon", null}
148AS OBJECT
149NULL
150AS ARRAY
151NULL
152Testing: ["Colon instead of comma": false]
153AS OBJECT
154NULL
155AS ARRAY
156NULL
157Testing: ["Bad value", truth]
158AS OBJECT
159NULL
160AS ARRAY
161NULL
162Testing: ['single quote']
163AS OBJECT
164NULL
165AS ARRAY
166NULL
167