mirror of
https://github.com/php/php-src.git
synced 2026-03-30 04:02:19 +02:00
This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines in all *.phpt sections. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
167 lines
4.9 KiB
PHP
167 lines
4.9 KiB
PHP
--TEST--
|
|
JSON (http://www.crockford.com/JSON/JSON_checker/test/fail*.json)
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded('json')) die('skip');
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
$tests = array(
|
|
'"A JSON payload should be an object or array, not a string."',
|
|
'["Unclosed array"',
|
|
'{unquoted_key: "keys must be quoted}',
|
|
'["extra comma",]',
|
|
'["double extra comma",,]',
|
|
'[ , "<-- missing value"]',
|
|
'["Comma after the close"],',
|
|
'["Extra close"]]',
|
|
'{"Extra comma": true,}',
|
|
'{"Extra value after close": true} "misplaced quoted value"',
|
|
'{"Illegal expression": 1 + 2}',
|
|
'{"Illegal invocation": alert()}',
|
|
'{"Numbers cannot have leading zeroes": 013}',
|
|
'{"Numbers cannot be hex": 0x14}',
|
|
'["Illegal backslash escape: \\x15"]',
|
|
'["Illegal backslash escape: \\\'"]',
|
|
'["Illegal backslash escape: \\017"]',
|
|
'[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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);
|
|
|
|
foreach ($tests as $test) {
|
|
echo 'Testing: ' . $test . "\n";
|
|
echo "AS OBJECT\n";
|
|
var_dump(json_decode($test));
|
|
echo "AS ARRAY\n";
|
|
var_dump(json_decode($test, true));
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
Testing: "A JSON payload should be an object or array, not a string."
|
|
AS OBJECT
|
|
string(58) "A JSON payload should be an object or array, not a string."
|
|
AS ARRAY
|
|
string(58) "A JSON payload should be an object or array, not a string."
|
|
Testing: ["Unclosed array"
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {unquoted_key: "keys must be quoted}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["extra comma",]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["double extra comma",,]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: [ , "<-- missing value"]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["Comma after the close"],
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["Extra close"]]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Extra comma": true,}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Extra value after close": true} "misplaced quoted value"
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Illegal expression": 1 + 2}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Illegal invocation": alert()}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Numbers cannot have leading zeroes": 013}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Numbers cannot be hex": 0x14}
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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Missing colon" null}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Double colon":: null}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: {"Comma instead of colon", null}
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["Colon instead of comma": false]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ["Bad value", truth]
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|
|
Testing: ['single quote']
|
|
AS OBJECT
|
|
NULL
|
|
AS ARRAY
|
|
NULL
|