-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.0.0: Fix bugs noticed while writing documentation
* Make the `SIMDJSON_ERR_*` constants case-sensitive in all PHP versions. (The code it was based on was missing the flag needed to mark constants as case sensitive before PHP 8) * Fix a bug that prevented using JSON pointer in `simdjson_key_count`, `simdjson_key_exists`, and `simdjson_key_value` with a leading slash https://www.rfc-editor.org/rfc/rfc6901.html. Fix a bug that was introduced when working around test failures following a change in json pointer validation in the underlying C simdjson library. * "" in a JSON pointer $key continues to refer to the entire document. * "/" in a JSON pointer $key now properly refer to the key that is the empty string. * Continue to allow the non-standard omission of the leading "/" for compatibility with earlier PECL releases. This may be deprecated in a subsequent release.
- Loading branch information
1 parent
7e41838
commit 4ac4c44
Showing
5 changed files
with
154 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--TEST-- | ||
simdjson_key_value with int test | ||
--SKIPIF-- | ||
<?php if (PHP_VERSION_ID < 70100) echo "skip requires php 7.1+ for empty string as object key\n"; | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . '/dump.inc'; | ||
$json = '{"":true,"code":123,"values":[{}],"obj":{"z": false}}'; | ||
$pointers = [ | ||
'/code', | ||
'/', | ||
'', | ||
'/code', | ||
'/code/0', | ||
'/code/x', | ||
'/values', | ||
'/values/0', | ||
'/values/1', | ||
'/values/-1', | ||
'/obj', | ||
'/obj/z', | ||
]; | ||
foreach ($pointers as $pointer) { | ||
echo "Test ", var_export($pointer, true), "\n"; | ||
dump(function () use ($json, $pointer) { return simdjson_key_value($json, $pointer, false); }); | ||
dump(function () use ($json, $pointer) { return simdjson_key_value($json, $pointer, true); }); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Test '/code' | ||
int(123) | ||
int(123) | ||
Test '/' | ||
bool(true) | ||
bool(true) | ||
Test '' | ||
object(stdClass)#2 (4) { | ||
[""]=> | ||
bool(true) | ||
["code"]=> | ||
int(123) | ||
["values"]=> | ||
array(1) { | ||
[0]=> | ||
object(stdClass)#3 (0) { | ||
} | ||
} | ||
["obj"]=> | ||
object(stdClass)#4 (1) { | ||
["z"]=> | ||
bool(false) | ||
} | ||
} | ||
array(4) { | ||
[""]=> | ||
bool(true) | ||
["code"]=> | ||
int(123) | ||
["values"]=> | ||
array(1) { | ||
[0]=> | ||
array(0) { | ||
} | ||
} | ||
["obj"]=> | ||
array(1) { | ||
["z"]=> | ||
bool(false) | ||
} | ||
} | ||
Test '/code' | ||
int(123) | ||
int(123) | ||
Test '/code/0' | ||
Caught SimdJsonException: Invalid JSON pointer syntax. | ||
Caught SimdJsonException: Invalid JSON pointer syntax. | ||
Test '/code/x' | ||
Caught SimdJsonException: Invalid JSON pointer syntax. | ||
Caught SimdJsonException: Invalid JSON pointer syntax. | ||
Test '/values' | ||
array(1) { | ||
[0]=> | ||
object(stdClass)#2 (0) { | ||
} | ||
} | ||
array(1) { | ||
[0]=> | ||
array(0) { | ||
} | ||
} | ||
Test '/values/0' | ||
object(stdClass)#2 (0) { | ||
} | ||
array(0) { | ||
} | ||
Test '/values/1' | ||
Caught SimdJsonException: Attempted to access an element of a JSON array that is beyond its length. | ||
Caught SimdJsonException: Attempted to access an element of a JSON array that is beyond its length. | ||
Test '/values/-1' | ||
Caught SimdJsonException: The JSON element does not have the requested type. | ||
Caught SimdJsonException: The JSON element does not have the requested type. | ||
Test '/obj' | ||
object(stdClass)#2 (1) { | ||
["z"]=> | ||
bool(false) | ||
} | ||
array(1) { | ||
["z"]=> | ||
bool(false) | ||
} | ||
Test '/obj/z' | ||
bool(false) | ||
bool(false) |