Code Monkey home page Code Monkey logo

pecl-jsonpath's People

Contributors

cmb69 avatar crocodele avatar danack avatar dawitnida avatar mk6i avatar remicollet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pecl-jsonpath's Issues

Handle lone booleans in filter expressions

Would maybe make sense to throw an exception for these?

Fixes for making the following tests pass:

  • comparison_filter/006.phpt: Test filter expression with boolean and operator and value false
  • comparison_filter/007.phpt: Test filter expression with boolean and operator and value true Moved to #59
  • comparison_filter/009.phpt: Test filter expression with boolean or operator and value false Moved to #59
  • comparison_filter/010.phpt: Test filter expression with boolean or operator and value true

jsonpath function always duplicates input string for unescaping

The main jsonpath() function always duplicates the input string passed to the lexer so that the lexer can modify the expression without modifying the input string. The lexer currently unescapes the input string by shifting characters. This was done in order to support escaped string literals in jsonpath. Duplicating the string requires a malloc() and corresponding free(). In order to improve overall performance of the extension, let's try to avoid this string duplication.

Performance improvements?

@crocodele I was wondering if you've seen any preliminary improvements in performance/resource usage by using this extension in your applications over PHP-based implementations?

Throw exception on invalid mix of dot and bracket notation

Fixes for making the following tests pass:

  • comparison_dot_notation/022.phpt: Test dot notation with double quotes
  • comparison_dot_notation/035.phpt: Test dot notation with single quotes
  • comparison_dot_notation/037.phpt: Test dot notation with single quotes and dot

Running child filter on recursive wildcard causes segfault

Found this problem with fuzz testing. The following query causes a segfault:

$query = "$..*['thor']";
(new \JsonPath\JsonPath())->find(array ("store" =>array ("book" =>array (0 =>array ("category" => "reference","title" => "Sayings of the Century","price" => 8.9499999999999993,"author" => "Nigel Rees",),1 =>array ("category" => "fiction","author" => "Evelyn Waugh","title" => "Sword of Honour","price" => 12.99,),2 =>array ("category" => "fiction","author" => "Herman Melville","title" => "Moby Dick","isbn" => "0-553-21311-3","price" => 8.9900000000000002,),3 =>array ("category" => "fiction","author" => "J. R. R. Tolkien","title" => "The Lord of the Rings","isbn" => "0-395-19395-8","price" => 22.989999999999998,),),"bicycle" =>array ("color" => "red","price" => 19.949999999999999,),"price" =>array (0 => 1,1 => 2,2 => 3,3 =>array (0 => 1,),4 =>array ("price" => "EMBEDDED",),),),"expensive" => 10,"title" => "WHAT","hello" =>array ("store" =>array (0 =>array ("title" => "HAH!",),),),"book" =>array (0 =>array ("category" => "reference","author" => "Nigel Rees","title" => "Sayings of the Century","price" => 8.9499999999999993,"id" =>array ("isbn" => "684832674",),),),), $query);

Support set-wise comparison

New feature for making the following tests pass:

  • comparison_filter/036.phpt: Test filter expression with equals number for bracket notation with star
  • comparison_filter/037.phpt: Test filter expression with equals number for dot notation with star
  • comparison_filter/059.phpt: Test filter expression with set wise comparison to scalar
  • comparison_filter/060.phpt: Test filter expression with set wise comparison to set

Null literal, multiplication, faulty equals, filter booleans, filter without parens

Fixes for making the following tests pass:

  • comparison_filter/034.phpt: Test filter expression with equals null
  • comparison_filter/053.phpt: Test filter expression with multiplication
  • comparison_filter/061.phpt: Test filter expression with single equal
  • comparison_filter/066.phpt: Test filter expression with triple equal
  • comparison_filter/070.phpt: Test filter expression with value false
  • comparison_filter/073.phpt: Test filter expression with value true
  • comparison_filter/074.phpt: Test filter expression without parens

Running index filter on non-array element causes segfault

The following query and array causes a segfault:

"$.*[61]"
['store']

Valgrind output:

==2052== Memcheck, a memory error detector
==2052== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2052== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==2052== Command: php test.php
==2052== 
==2052== Invalid read of size 4
==2052==    at 0x745564: _zend_is_inconsistent (zend_hash.c:54)
==2052==    by 0x74CD7A: zend_hash_index_find (zend_hash.c:2251)
==2052==    by 0x48502BF: exec_index_filter (interpreter.c:151)
==2052==    by 0x484FB0D: eval_ast (interpreter.c:41)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FE67: exec_wildcard (interpreter.c:97)
==2052==    by 0x484FBA3: eval_ast (interpreter.c:58)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FB47: eval_ast (interpreter.c:48)
==2052==    by 0x484C9C9: zim_JsonPath_JsonPath_find (jsonpath.c:82)
==2052==    by 0x7A805D: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==2052==    by 0x8130D3: execute_ex (zend_vm_execute.h:53521)
==2052==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==2052== 
==2052== 
==2052== Process terminating with default action of signal 11 (SIGSEGV)
==2052==  Access not within mapped region at address 0x8
==2052==    at 0x745564: _zend_is_inconsistent (zend_hash.c:54)
==2052==    by 0x74CD7A: zend_hash_index_find (zend_hash.c:2251)
==2052==    by 0x48502BF: exec_index_filter (interpreter.c:151)
==2052==    by 0x484FB0D: eval_ast (interpreter.c:41)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FE67: exec_wildcard (interpreter.c:97)
==2052==    by 0x484FBA3: eval_ast (interpreter.c:58)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FB47: eval_ast (interpreter.c:48)
==2052==    by 0x484C9C9: zim_JsonPath_JsonPath_find (jsonpath.c:82)
==2052==    by 0x7A805D: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==2052==    by 0x8130D3: execute_ex (zend_vm_execute.h:53521)
==2052==  If you believe this happened as a result of a stack
==2052==  overflow in your program's main thread (unlikely but
==2052==  possible), you can try to increase the size of the
==2052==  main thread stack using the --main-stacksize= flag.
==2052==  The main thread stack size used in this run was 8388608.
==2052== 
==2052== HEAP SUMMARY:
==2052==     in use at exit: 1,331,744 bytes in 10,391 blocks
==2052==   total heap usage: 11,028 allocs, 637 frees, 1,694,354 bytes allocated
==2052== 
==2052== LEAK SUMMARY:
==2052==    definitely lost: 24 bytes in 1 blocks
==2052==    indirectly lost: 0 bytes in 0 blocks
==2052==      possibly lost: 1,068,728 bytes in 9,221 blocks
==2052==    still reachable: 262,992 bytes in 1,169 blocks
==2052==         suppressed: 0 bytes in 0 blocks
==2052== Rerun with --leak-check=full to see details of leaked memory
==2052== 
==2052== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==2052== 
==2052== 1 errors in context 1 of 1:
==2052== Invalid read of size 4
==2052==    at 0x745564: _zend_is_inconsistent (zend_hash.c:54)
==2052==    by 0x74CD7A: zend_hash_index_find (zend_hash.c:2251)
==2052==    by 0x48502BF: exec_index_filter (interpreter.c:151)
==2052==    by 0x484FB0D: eval_ast (interpreter.c:41)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FE67: exec_wildcard (interpreter.c:97)
==2052==    by 0x484FBA3: eval_ast (interpreter.c:58)
==2052==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==2052==    by 0x484FB47: eval_ast (interpreter.c:48)
==2052==    by 0x484C9C9: zim_JsonPath_JsonPath_find (jsonpath.c:82)
==2052==    by 0x7A805D: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==2052==    by 0x8130D3: execute_ex (zend_vm_execute.h:53521)
==2052==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==2052== 
==2052== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

AST dump:

--------------------------------------
Lexer - Processed tokens

	• LEX_ROOT
	• LEX_WILD_CARD
	• LEX_FILTER_START
	• LEX_LITERAL_NUMERIC [val=61]
	• LEX_EXPR_END
--------------------------------------
Parser - AST sent to interpreter

	➔ AST_WILD_CARD
	➔ AST_INDEX_LIST

config.w32 is missing from PECL package (0.9.3)

Although config.w32 is part of the repository, for some reason it is missing from the PECL package jsonpath-0.9.3.tgz; that prevents the Windows DLLs to be build on the PECL build machine.

Documentation needs some initial tweaks

  • The "Usage" and "Examples" sections should use the JsonPath class, not the path_lookup() function
  • The CI badge should point to GitHub actions instead of Travis CI <-- fixed in #8
  • Mention new maintainers, give credit to original project creator Mike

Fix assorted JSONPath Comparison tests, vol. 1

Fixes for making the following uncategorized tests pass:

  • comparison_filter/013.phpt: Test filter expression with bracket notation with -1
  • comparison_filter/014.phpt: Test filter expression with bracket notation with number
  • comparison_filter/015.phpt: Test filter expression with bracket notation with number on object
  • comparison_filter/024.phpt: Test filter expression with equals on array of numbers

Support union with one or more string or expression keys

Fixes for making the following tests pass:

  • comparison_dot_notation/020.phpt: Test dot notation after union with keys
  • comparison_union/004.phpt: Test union with filter
  • comparison_union/003.phpt: Test union with duplication from object
  • comparison_union/005.phpt: Test union with keys
  • comparison_union/006.phpt: Test union with keys on object without key
  • comparison_union/007.phpt: Test union with keys after array slice
  • comparison_union/008.phpt: Test union with keys after bracket notation
  • comparison_union/009.phpt: Test union with keys after dot notation with wildcard
  • comparison_union/010.phpt: Test union with keys after recursive descent

Fuzz testing yields 231 inputs that cause segfaults

I ran fuzz testing on the extension by following this guide.

The test ran for 1 hour and the corpus consisted of a single entry:

$.store.book[?(@.author == "Herman Melville" && @.title == "Moby Dick" || @.author == "Evelyn Waugh")]

This is the command I ran (which pulls the JSONPath query from stdin):

afl-fuzz -M fuzzer01 -i fuzz_input/ -o basic_fuzz -m none -- php -r '(new \JsonPath\JsonPath())->find(array ("store" =>array ("book" =>array (0 =>array ("category" => "reference","title" => "Sayings of the Century","price" => 8.9499999999999993,"author" => "Nigel Rees",),1 =>array ("category" => "fiction","author" => "Evelyn Waugh","title" => "Sword of Honour","price" => 12.99,),2 =>array ("category" => "fiction","author" => "Herman Melville","title" => "Moby Dick","isbn" => "0-553-21311-3","price" => 8.9900000000000002,),3 =>array ("category" => "fiction","author" => "J. R. R. Tolkien","title" => "The Lord of the Rings","isbn" => "0-395-19395-8","price" => 22.989999999999998,),),"bicycle" =>array ("color" => "red","price" => 19.949999999999999,),"price" =>array (0 => 1,1 => 2,2 => 3,3 =>array (0 => 1,),4 =>array ("price" => "EMBEDDED",),),),"expensive" => 10,"title" => "WHAT","hello" =>array ("store" =>array (0 =>array ("title" => "HAH!",),),),"book" =>array (0 =>array ("category" => "reference","author" => "Nigel Rees","title" => "Sayings of the Century","price" => 8.9499999999999993,"id" =>array ("isbn" => "684832674",),),),), file_get_contents("php://stdin"));

Attached is a complete list of the failed JSONPath queries. Note that each entry consists of a string of all the printable characters and a base64 encoding that contains both printable/non-printable characters.

failed_queries.txt

Mix of array indexes and keys in union filter causes segfault

The following query causes a segfault:

$obj = [
    'key' => [
        'val' => 1
    ]
];

$jsonPath = new \JsonPath\JsonPath();
$jsonPath->find($obj, "$..['val'2]");

Valgrind output:

==1982== Memcheck, a memory error detector
==1982== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1982== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==1982== Command: php test.php
==1982== 
==1982== Invalid read of size 8
==1982==    at 0x48500C1: exec_node_filter (interpreter.c:125)
==1982==    by 0x484FB4A: eval_ast (interpreter.c:38)
==1982==    by 0x484FF3E: exec_recursive_descent (interpreter.c:110)
==1982==    by 0x484FBC9: eval_ast (interpreter.c:52)
==1982==    by 0x4850CC8: copy_result_or_continue (interpreter.c:353)
==1982==    by 0x484FBA1: eval_ast (interpreter.c:48)
==1982==    by 0x484C9C9: zim_JsonPath_JsonPath_find (jsonpath.c:82)
==1982==    by 0x7A805D: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==1982==    by 0x8130D3: execute_ex (zend_vm_execute.h:53521)
==1982==    by 0x818072: zend_execute (zend_vm_execute.h:57617)
==1982==    by 0x7328CA: zend_execute_scripts (zend.c:1679)
==1982==    by 0x692018: php_execute_script (main.c:2658)
==1982==  Address 0x12 is not stack'd, malloc'd or (recently) free'd
==1982== 
==1982== 
==1982== Process terminating with default action of signal 11 (SIGSEGV)
==1982==  Access not within mapped region at address 0x12
==1982==    at 0x48500C1: exec_node_filter (interpreter.c:125)
==1982==    by 0x484FB4A: eval_ast (interpreter.c:38)
==1982==    by 0x484FF3E: exec_recursive_descent (interpreter.c:110)
==1982==    by 0x484FBC9: eval_ast (interpreter.c:52)
==1982==    by 0x4850CC8: copy_result_or_continue (interpreter.c:353)
==1982==    by 0x484FBA1: eval_ast (interpreter.c:48)
==1982==    by 0x484C9C9: zim_JsonPath_JsonPath_find (jsonpath.c:82)
==1982==    by 0x7A805D: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:1618)
==1982==    by 0x8130D3: execute_ex (zend_vm_execute.h:53521)
==1982==    by 0x818072: zend_execute (zend_vm_execute.h:57617)
==1982==    by 0x7328CA: zend_execute_scripts (zend.c:1679)
==1982==    by 0x692018: php_execute_script (main.c:2658)
==1982==  If you believe this happened as a result of a stack
==1982==  overflow in your program's main thread (unlikely but
==1982==  possible), you can try to increase the size of the
==1982==  main thread stack using the --main-stacksize= flag.
==1982==  The main thread stack size used in this run was 8388608.
==1982== 
==1982== HEAP SUMMARY:
==1982==     in use at exit: 1,331,744 bytes in 10,391 blocks
==1982==   total heap usage: 11,028 allocs, 637 frees, 1,694,354 bytes allocated
==1982== 
==1982== LEAK SUMMARY:
==1982==    definitely lost: 24 bytes in 1 blocks
==1982==    indirectly lost: 0 bytes in 0 blocks
==1982==      possibly lost: 1,068,728 bytes in 9,221 blocks
==1982==    still reachable: 262,992 bytes in 1,169 blocks
==1982==         suppressed: 0 bytes in 0 blocks
==1982== Rerun with --leak-check=full to see details of leaked memory
==1982== 
==1982== For lists of detected and suppressed errors, rerun with: -s
==1982== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

AST dump:

--------------------------------------
Lexer - Processed tokens

	• LEX_ROOT
	• LEX_DEEP_SCAN
	• LEX_FILTER_START
	• LEX_LITERAL [val=val]
	• LEX_LITERAL_NUMERIC [val=2]
	• LEX_EXPR_END
--------------------------------------
Parser - AST sent to interpreter

	➔ AST_RECURSE
	➔ AST_NODE_LIST

Create a flow for PECL releases

Just before tagging a new release, we should always update the version number in php_jsonpath.h, update the package.xml with the changelog, build the PEAR package, and upload it to PECL. This process should be automated as much as possible.

Support negation

New feature for making the following tests pass:

  • comparison_filter/054.phpt: Test filter expression with negation and equals
  • comparison_filter/055.phpt: Test filter expression with negation and less than Moved to #59
  • comparison_filter/075.phpt: Test filter expression without value

Consolidate 2 boolean AST tokens into 1

After refactoring, there are now two different types of boolean AST tokens: AST_BOOL and AST_LITERAL_BOOL. AST_BOOL is used created to store intermediate results during expression evaluation, and AST_LITERAL_BOOL is created for true/false values in the expression. The new parser doesn't actually evaluate AST_LITERAL_BOOL, so boolean values are ignored by the interpreter. There's no particular reason for this, other than it being an oversight on my part.

This change should fix the following tests:

  • ./tests/comparison_filter/032.php:$result = $jsonPath->find($data, "$[?((@.key<44)==false)]");
  • ./tests/comparison_filter/033.php:$result = $jsonPath->find($data, "$[?(@.key==false)]");
  • ./tests/comparison_filter/045.php:$result = $jsonPath->find($data, "$[?(@.key==true)]");

Support array syntax

New feature for making the following tests pass:

  • comparison_filter/028.phpt: Test filter expression with equals array
  • comparison_filter/029.phpt: Test filter expression with equals array for array slice with range 1
  • comparison_filter/030.phpt: Test filter expression with equals array for dot notation with star
  • comparison_filter/031.phpt: Test filter expression with equals array with single quotes

Missing left-hand operand causes segfault

The following query causes a segfault (found with the help of fuzz testing in #142):

'$.store.book[?(@.author == "Herman Melville" &&<@.t)tle == "Moby Dick" || @.or == "Evelyn Wa")]'

Valgrind report:

==137361== Memcheck, a memory error detector
==137361== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==137361== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==137361== Command: php test.php
==137361== 
==137361== Invalid read of size 4
==137361==    at 0x4850F5B: evaluate_operand (interpreter.c:407)
==137361==    by 0x4851177: evaluate_binary (interpreter.c:443)
==137361==    by 0x4850F7F: evaluate_operand (interpreter.c:408)
==137361==    by 0x48511CC: evaluate_binary (interpreter.c:451)
==137361==    by 0x4850CB4: evaluate_expression (interpreter.c:355)
==137361==    by 0x485077B: exec_expression (interpreter.c:245)
==137361==    by 0x484FBBD: eval_ast (interpreter.c:61)
==137361==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==137361==    by 0x484FD3B: exec_selector (interpreter.c:85)
==137361==    by 0x484FB89: eval_ast (interpreter.c:55)
==137361==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==137361==    by 0x484FD3B: exec_selector (interpreter.c:85)
==137361==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==137361== 
==137361== 
==137361== Process terminating with default action of signal 11 (SIGSEGV)
==137361==  Access not within mapped region at address 0x8
==137361==    at 0x4850F5B: evaluate_operand (interpreter.c:407)
==137361==    by 0x4851177: evaluate_binary (interpreter.c:443)
==137361==    by 0x4850F7F: evaluate_operand (interpreter.c:408)
==137361==    by 0x48511CC: evaluate_binary (interpreter.c:451)
==137361==    by 0x4850CB4: evaluate_expression (interpreter.c:355)
==137361==    by 0x485077B: exec_expression (interpreter.c:245)
==137361==    by 0x484FBBD: eval_ast (interpreter.c:61)
==137361==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==137361==    by 0x484FD3B: exec_selector (interpreter.c:85)
==137361==    by 0x484FB89: eval_ast (interpreter.c:55)
==137361==    by 0x4850C4D: copy_result_or_continue (interpreter.c:349)
==137361==    by 0x484FD3B: exec_selector (interpreter.c:85)
==137361==  If you believe this happened as a result of a stack
==137361==  overflow in your program's main thread (unlikely but
==137361==  possible), you can try to increase the size of the
==137361==  main thread stack using the --main-stacksize= flag.
==137361==  The main thread stack size used in this run was 8388608.
==137361== 
==137361== HEAP SUMMARY:
==137361==     in use at exit: 1,331,752 bytes in 10,391 blocks
==137361==   total heap usage: 11,028 allocs, 637 frees, 1,694,362 bytes allocated
==137361== 
==137361== LEAK SUMMARY:
==137361==    definitely lost: 24 bytes in 1 blocks
==137361==    indirectly lost: 0 bytes in 0 blocks
==137361==      possibly lost: 1,068,728 bytes in 9,221 blocks
==137361==    still reachable: 263,000 bytes in 1,169 blocks
==137361==         suppressed: 0 bytes in 0 blocks
==137361== Rerun with --leak-check=full to see details of leaked memory
==137361== 
==137361== For lists of detected and suppressed errors, rerun with: -s
==137361== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)

AST dump:

Parser - AST sent to interpreter

	➔ AST_SELECTOR [val=store] [val=book]
	➔ AST_EXPR
		➔ AST_AND
			➔ AST_EQ
				➔ AST_CUR_NODE
				➔ AST_SELECTOR [val=author]
				➔ AST_LITERAL [val=Herman Melville]
			➔ AST_LT
				➔ AST_CUR_NODE
				➔ AST_SELECTOR [val=t]

In this query, the < operator is missing a left-hand operand. The interpreter triggers a segfault when it tries to recurse on the < operator's missing left-hand operand.

Throw exception on various funny selectors

Fixes for making the following tests pass:

  • comparison_dot_notation/024.phpt: Test dot notation with empty path
  • comparison_dot_notation/038.phpt: Test dot notation with space padded key

Handle some more cases of strict comparisons

Probably best to leverage PHP's strict comparison here too.

Fixes for making the following tests pass:

  • comparison_filter/007.phpt: Test filter expression with boolean and operator and value true
  • comparison_filter/009.phpt: Test filter expression with boolean or operator and value false
  • comparison_filter/047.phpt: Test filter expression with greater than
  • comparison_filter/048.phpt: Test filter expression with greater than or equal
  • comparison_filter/051.phpt: Test filter expression with less than
  • comparison_filter/052.phpt: Test filter expression with less than or equal
  • comparison_filter/055.phpt: Test filter expression with negation and less than
  • comparison_filter/056.phpt: Test filter expression with not equals

10% of CPU time is spent on node allocation

I created a small benchmark that iterates tests/001.phpt 10000 times without printing and ran it through perf. The results indicate that 10% of CPU time is spent allocating AST nodes.

Screen Shot 2021-06-04 at 9 35 24 AM

emalloc() is called for each new node. We can probably reduce this bottleneck by either allocating nodes in chunks or simply using a stack-allocated array. This might make it possible to bring performance closer to the native PHP test for small/medium data sets.

Values assigned by reference are not found

When a value is assigned by reference, the engine doesn't find it properly. Example:

<?php

$data = [
    "key" => 42,
];

$another = [
    "key" => 43,
];

$data["another"] =& $another;

$jsonPath = new \JsonPath\JsonPath();

$result = $jsonPath->find($data, "$.another.key");
var_dump($result); // bool(false)

$result = $jsonPath->find($data, "$['another']['key']");
// segfault

Build fails on PHP 8.4

Looks like there are some changes required in the regex handling in order to support PHP 8.4. From the build logs:

Run ./.build-scripts/compile.sh
  ./.build-scripts/compile.sh
  shell: /usr/bin/bash -e {0}
  env:
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
Configuring for:
PHP Version:             8.4
PHP Api Version:         20230901
Zend Module Api No:      20230901
Zend Extension Api No:   420230901
configure.ac:165: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.ac:165: You should run autoupdate.
build/libtool.m4:99: AC_PROG_LIBTOOL is expanded from...
configure.ac:165: the top level
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20230901
checking for PHP installed headers prefix... /usr/include/php/20230901
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking whether to enable JSONPath support... yes, shared
checking whether to enable code coverage (relevant for extension development only!)... no
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 3145728
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
/bin/bash /home/runner/work/pecl-jsonpath/pecl-jsonpath/libtool --mode=compile cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/jsonpath.c -o jsonpath.lo  -MMD -MF jsonpath.dep -MT jsonpath.lo
libtool: compile:  cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/jsonpath.c -MMD -MF jsonpath.dep -MT jsonpath.lo  -fPIC -DPIC -o .libs/jsonpath.o
/bin/bash /home/runner/work/pecl-jsonpath/pecl-jsonpath/libtool --mode=compile cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/exceptions.c -o src/jsonpath/exceptions.lo  -MMD -MF src/jsonpath/exceptions.dep -MT src/jsonpath/exceptions.lo
libtool: compile:  cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/exceptions.c -MMD -MF src/jsonpath/exceptions.dep -MT src/jsonpath/exceptions.lo  -fPIC -DPIC -o src/jsonpath/.libs/exceptions.o
/bin/bash /home/runner/work/pecl-jsonpath/pecl-jsonpath/libtool --mode=compile cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/lexer.c -o src/jsonpath/lexer.lo  -MMD -MF src/jsonpath/lexer.dep -MT src/jsonpath/lexer.lo
libtool: compile:  cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/lexer.c -MMD -MF src/jsonpath/lexer.dep -MT src/jsonpath/lexer.lo  -fPIC -DPIC -o src/jsonpath/.libs/lexer.o
/bin/bash /home/runner/work/pecl-jsonpath/pecl-jsonpath/libtool --mode=compile cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/parser.c -o src/jsonpath/parser.lo  -MMD -MF src/jsonpath/parser.dep -MT src/jsonpath/parser.lo
libtool: compile:  cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/parser.c -MMD -MF src/jsonpath/parser.dep -MT src/jsonpath/parser.lo  -fPIC -DPIC -o src/jsonpath/.libs/parser.o
/bin/bash /home/runner/work/pecl-jsonpath/pecl-jsonpath/libtool --mode=compile cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib  -DHAVE_CONFIG_H  -g -O2 -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/interpreter.c -o src/jsonpath/interpreter.lo  -MMD -MF src/jsonpath/interpreter.dep -MT src/jsonpath/interpreter.lo
libtool: compile:  cc -I. -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/include -I/home/runner/work/pecl-jsonpath/pecl-jsonpath/main -I/home/runner/work/pecl-jsonpath/pecl-jsonpath -I/usr/include/php/20230901 -I/usr/include/php/20230901/main -I/usr/include/php/20230901/TSRM -I/usr/include/php/20230901/Zend -I/usr/include/php/20230901/ext -I/usr/include/php/20230901/ext/date/lib -DHAVE_CONFIG_H -g -O2 -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/interpreter.c -MMD -MF src/jsonpath/interpreter.dep -MT src/jsonpath/interpreter.lo  -fPIC -DPIC -o src/jsonpath/.libs/interpreter.o
/home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/interpreter.c: In function ‘compare_rgxp’:
/home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/interpreter.c:296:3: error: too many arguments to function ‘php_pcre_match_impl’
  296 |   php_pcre_match_impl(pce, zs_lh, &retval, &subpats, 0, 0, 0, 0);
      |   ^~~~~~~~~~~~~~~~~~~
In file included from /home/runner/work/pecl-jsonpath/pecl-jsonpath/src/jsonpath/interpreter.c:4:
/usr/include/php/20230901/ext/pcre/php_pcre.h:52:14: note: declared here
   52 | PHPAPI void  php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
      |              ^~~~~~~~~~~~~~~~~~~
make: *** [Makefile:243: src/jsonpath/interpreter.lo] Error 1
Error: Process completed with exit code 2.

Fix assorted JSONPath Comparison tests, vol. 2

Fixes for making the following uncategorized tests pass:

  • comparison_filter/035.phpt: Test filter expression with equals number for array slice with range 1
  • comparison_filter/040.phpt: Test filter expression with equals object
  • comparison_filter/057.phpt: Test filter expression with regular expression
  • comparison_filter/071.phpt: Test filter expression with value from recursive descent
  • comparison_root/001.phpt: Test root

Support more reserved characters in selectors and filter expressions

Fixes for making the following tests pass:

  • comparison_bracket_notation/029.phpt: Test bracket notation with quoted special characters combined
  • comparison_dot_notation/030.phpt: Test dot notation with key root literal
  • comparison_filter/016.phpt: Test filter expression with current object

The extension code should be wrapped in a namespace

It's desirable that extensions now use a namespace:

  • Extensions should not use a vendor namespace.
  • The top-level namespace should match the extension name (apart from casing).
  • Namespace names should follow CamelCase.
  • All symbols defined in the extension should be part of the extension's top-level namespace or a sub-namespace.

https://wiki.php.net/rfc/namespaces_in_bundled_extensions

Following the above guidelines, JsonPath would be the logical name choice for the namespace.

Split up tasks?

@crocodele I've been fixing picking out tests to fix at random, and I imagine that could make it difficult for you to take time to work on what you're interested in. Is there a subset of the tests that you want to reserve for yourself?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.