pecl-jsonpath icon indicating copy to clipboard operation
pecl-jsonpath copied to clipboard

Segmentation faullt on regex

Open AlexanderWelberg opened this issue 1 year ago • 1 comments

Hi,

you have several issues connected to data types and conditionals:

  1. Segmentation Fault on Regex: When executing jsonpath like $.items[?( @.quantity =~ /[0-9]*/)] when quantity is a json number
  2. No return using condition $.items[?( @.quantity > 0)] and quantity is a string number like "1" or "2"
  3. Returns all items when condition is $.items[?( @.quantity >= 0)] and quantity is a string number like "1" or "2"

The first one is really bad, please fix asap. The other two should be fixed, because jsonpath condition numeric comparisons do not rely on numbers only.

Thanks

AlexanderWelberg avatar Oct 02 '24 16:10 AlexanderWelberg

Thanks for reporting. I’ll work on a fix when I free up in a few weeks, unless someone else wants to start on one sooner.

mk6i avatar Oct 02 '24 22:10 mk6i

(1.) was fixed in v2.1.1, and (2.) and (3.) were addressed in v3.0.0. I'm going to close this issue; if you notice any related problems (or other problems 🙂), feel free to create a new issue.

crocodele avatar Jan 29 '25 13:01 crocodele

great, it works. Thanks for the update! simple test: php $found=((new JsonPath()) ->find( [ 'items' => [ [ 'id' => "1 is ok", 'quantity' => 1, ], [ 'id' => "2 is ok", 'quantity' => 2, ], [ 'id' => "3 is not ok", 'quantity' => "qwe", ] ] ], '$.items[?( @.quantity =~ /[0-9]+/)].id' ) ); var_dump($found); return; results in array(2) { [0]=> string(7) "1 is ok" [1]=> string(7) "2 is ok" }

AlexanderWelberg avatar Jan 29 '25 13:01 AlexanderWelberg