mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

* Add `json_validate(string $json, int $depth = 512, int $flags = 0): bool` from https://wiki.php.net/rfc/json_validate * In json_validate, use a different set of C no-op functions for creating/updating arrays/objects when validating while reusing the unmodified parser/scanner code * Forbid unsupported flags in json_validate() * Remove test of passing NULL as parameter (normal behavior of https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg for internal functions) Co-authored-by: jcm <juan.carlos.morales@tradebyte.com>
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
--TEST--
|
|
json_validate() - Error handling
|
|
--FILE--
|
|
<?php
|
|
|
|
require_once("json_validate_requires.inc");
|
|
|
|
json_validate_trycatchdump("");
|
|
json_validate_trycatchdump("-");
|
|
json_validate_trycatchdump("", -1);
|
|
json_validate_trycatchdump('{"key1":"value1", "key2":"value2"}', 1);
|
|
json_validate_trycatchdump('{"key1":"value1", "key2":"value2"}', 2);
|
|
json_validate_trycatchdump("-", 0);
|
|
json_validate_trycatchdump("-", 512, JSON_BIGINT_AS_STRING);
|
|
json_validate_trycatchdump("-", 512, JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE);
|
|
json_validate_trycatchdump("-", 512, JSON_INVALID_UTF8_IGNORE);
|
|
json_validate_trycatchdump("{}", 512, JSON_INVALID_UTF8_IGNORE);
|
|
|
|
?>
|
|
--EXPECTF--
|
|
bool(false)
|
|
int(4)
|
|
string(12) "Syntax error"
|
|
bool(false)
|
|
int(4)
|
|
string(12) "Syntax error"
|
|
bool(false)
|
|
int(4)
|
|
string(12) "Syntax error"
|
|
bool(false)
|
|
int(1)
|
|
string(28) "Maximum stack depth exceeded"
|
|
bool(true)
|
|
int(0)
|
|
string(8) "No error"
|
|
Error: 0 json_validate(): Argument #2 ($depth) must be greater than 0
|
|
int(0)
|
|
string(8) "No error"
|
|
Error: 0 json_validate(): Argument #3 ($flags) must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)
|
|
int(0)
|
|
string(8) "No error"
|
|
Error: 0 json_validate(): Argument #3 ($flags) must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)
|
|
int(0)
|
|
string(8) "No error"
|
|
bool(false)
|
|
int(4)
|
|
string(12) "Syntax error"
|
|
bool(true)
|
|
int(0)
|
|
string(8) "No error"
|