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