fail001.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. --TEST--
  2. JSON (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. $tests = array(
  10. '"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. );
  35. foreach ($tests as $test) {
  36. echo 'Testing: ' . $test . "\n";
  37. echo "AS OBJECT\n";
  38. var_dump(json_decode($test));
  39. echo "AS ARRAY\n";
  40. var_dump(json_decode($test, true));
  41. }
  42. ?>
  43. --EXPECT--
  44. Testing: "A JSON payload should be an object or array, not a string."
  45. AS OBJECT
  46. string(58) "A JSON payload should be an object or array, not a string."
  47. AS ARRAY
  48. string(58) "A JSON payload should be an object or array, not a string."
  49. Testing: ["Unclosed array"
  50. AS OBJECT
  51. NULL
  52. AS ARRAY
  53. NULL
  54. Testing: {unquoted_key: "keys must be quoted}
  55. AS OBJECT
  56. NULL
  57. AS ARRAY
  58. NULL
  59. Testing: ["extra comma",]
  60. AS OBJECT
  61. NULL
  62. AS ARRAY
  63. NULL
  64. Testing: ["double extra comma",,]
  65. AS OBJECT
  66. NULL
  67. AS ARRAY
  68. NULL
  69. Testing: [ , "<-- missing value"]
  70. AS OBJECT
  71. NULL
  72. AS ARRAY
  73. NULL
  74. Testing: ["Comma after the close"],
  75. AS OBJECT
  76. NULL
  77. AS ARRAY
  78. NULL
  79. Testing: ["Extra close"]]
  80. AS OBJECT
  81. NULL
  82. AS ARRAY
  83. NULL
  84. Testing: {"Extra comma": true,}
  85. AS OBJECT
  86. NULL
  87. AS ARRAY
  88. NULL
  89. Testing: {"Extra value after close": true} "misplaced quoted value"
  90. AS OBJECT
  91. NULL
  92. AS ARRAY
  93. NULL
  94. Testing: {"Illegal expression": 1 + 2}
  95. AS OBJECT
  96. NULL
  97. AS ARRAY
  98. NULL
  99. Testing: {"Illegal invocation": alert()}
  100. AS OBJECT
  101. NULL
  102. AS ARRAY
  103. NULL
  104. Testing: {"Numbers cannot have leading zeroes": 013}
  105. AS OBJECT
  106. NULL
  107. AS ARRAY
  108. NULL
  109. Testing: {"Numbers cannot be hex": 0x14}
  110. AS OBJECT
  111. NULL
  112. AS ARRAY
  113. NULL
  114. Testing: ["Illegal backslash escape: \x15"]
  115. AS OBJECT
  116. NULL
  117. AS ARRAY
  118. NULL
  119. Testing: ["Illegal backslash escape: \'"]
  120. AS OBJECT
  121. NULL
  122. AS ARRAY
  123. NULL
  124. Testing: ["Illegal backslash escape: \017"]
  125. AS OBJECT
  126. NULL
  127. AS ARRAY
  128. NULL
  129. Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
  130. AS OBJECT
  131. NULL
  132. AS ARRAY
  133. NULL
  134. Testing: {"Missing colon" null}
  135. AS OBJECT
  136. NULL
  137. AS ARRAY
  138. NULL
  139. Testing: {"Double colon":: null}
  140. AS OBJECT
  141. NULL
  142. AS ARRAY
  143. NULL
  144. Testing: {"Comma instead of colon", null}
  145. AS OBJECT
  146. NULL
  147. AS ARRAY
  148. NULL
  149. Testing: ["Colon instead of comma": false]
  150. AS OBJECT
  151. NULL
  152. AS ARRAY
  153. NULL
  154. Testing: ["Bad value", truth]
  155. AS OBJECT
  156. NULL
  157. AS ARRAY
  158. NULL
  159. Testing: ['single quote']
  160. AS OBJECT
  161. NULL
  162. AS ARRAY
  163. NULL