xref: /PHP-7.2/ext/json/tests/bug64874_part1.phpt (revision e5abc537)
1--TEST--
2Whitespace part of bug #64874 ("json_decode handles whitespace and case-sensitivity incorrectly")
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7function decode($json) {
8	var_dump(json_decode($json));
9	var_dump(json_last_error() !== 0);
10	echo "\n";
11}
12
13// Leading whitespace should be ignored
14decode(" true");
15decode("\ttrue");
16decode("\ntrue");
17decode("\rtrue");
18
19// So should trailing whitespace
20decode("true ");
21decode("true\t");
22decode("true\n");
23decode("true\r");
24
25// And so should the combination of both
26decode(" true ");
27decode(" true\t");
28decode(" true\n");
29decode(" true\r");
30decode("\ttrue ");
31decode("\ttrue\t");
32decode("\ttrue\n");
33decode("\ttrue\r");
34decode("\ntrue ");
35decode("\ntrue\t");
36decode("\ntrue\n");
37decode("\ntrue\r");
38decode("\rtrue ");
39decode("\rtrue\t");
40decode("\rtrue\n");
41decode("\rtrue\r");
42
43echo "Done\n";
44--EXPECT--
45bool(true)
46bool(false)
47
48bool(true)
49bool(false)
50
51bool(true)
52bool(false)
53
54bool(true)
55bool(false)
56
57bool(true)
58bool(false)
59
60bool(true)
61bool(false)
62
63bool(true)
64bool(false)
65
66bool(true)
67bool(false)
68
69bool(true)
70bool(false)
71
72bool(true)
73bool(false)
74
75bool(true)
76bool(false)
77
78bool(true)
79bool(false)
80
81bool(true)
82bool(false)
83
84bool(true)
85bool(false)
86
87bool(true)
88bool(false)
89
90bool(true)
91bool(false)
92
93bool(true)
94bool(false)
95
96bool(true)
97bool(false)
98
99bool(true)
100bool(false)
101
102bool(true)
103bool(false)
104
105bool(true)
106bool(false)
107
108bool(true)
109bool(false)
110
111bool(true)
112bool(false)
113
114bool(true)
115bool(false)
116
117Done
118