fail001.phpt 4.9 KB

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