json-machine icon indicating copy to clipboard operation
json-machine copied to clipboard

Fix the parsing of nested sub-trees that use wildcards

Open cerbero90 opened this issue 3 years ago β€’ 5 comments

Hey @halaxa! Long time since our last PR! πŸ˜„

Your package keeps improving, I love the support for multiple JSON pointers ❀️

While updating my package (based on yours), I noticed that some changes are interrupting the iteration of nested sub-trees at the first matching JSON object and ignore the remaining iterations. Which appears to be the issue flagged here: https://github.com/halaxa/json-machine/issues/78

This PR aims to bring the following changes:

  • let indexes of JSON arrays be integer within the current path. This brings 2 benefits:
    • accurate current path, JSON array indexes are actually integers
    • avoid the use of regular expressions to perform checks against parts of the path
  • fix how we compute the current path and current path wildcard
    • currently these paths are not cleaned when the current level drops by 2 or more levels
  • fix the parsing of nested sub-trees that use wildcards
    • currently they are interrupted after the first iteration
  • simplify and make the logic to compute the matching JSON pointer more accurate
  • improve and add one more test for parsing nested sub-trees using wildcards

cerbero90 avatar May 23 '22 14:05 cerbero90

Hi, nice to see you again :) I'll be able to engage in about a week. Thank you very much for pushing it further.

(To be honest, I intend to rewrite the whole Parser from scratch, it's getting a little messy. But it's hard to say when I get to it...)

halaxa avatar May 29 '22 10:05 halaxa

Hi @halaxa, no worries :) Do you plan to rewrite the parser before tackling this PR or you are thinking of rewriting it at a later stage?

cerbero90 avatar Jun 18 '22 02:06 cerbero90

I'm sorry for not replying. I'm currently a little busy with some voluntary work. I'm not sure when I get to this PR. But at the first look, I like that some of the messier code is gone πŸ‘. In the meanwhile, could you rename "json pointer segment" to "reference token" for less confusion? It's the official designation: https://datatracker.ietf.org/doc/html/rfc6901#section-3. Thanks ;)

halaxa avatar Jul 13 '22 10:07 halaxa

Although I know you didn't break it, making the build work could be a valuable meanwhile-contribution as well 😁.

halaxa avatar Jul 13 '22 10:07 halaxa

No worries at all, take your time :)

I renamed the variables as you suggested, I guess the issue with the build is related to the conflict between the versions of PHP and composer:

Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.0.33

You may consider to either add matrices to the build script or drop support for old versions of PHP

cerbero90 avatar Jul 13 '22 22:07 cerbero90

Merged the build fix from master with the fix for the composer version. make build works now.

halaxa avatar Sep 30 '22 16:09 halaxa

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage :thumbsup:

Coverage data is based on head (50aeebe) compared to base (21057a6). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##              master       #83   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       181       184    +3     
===========================================
  Files             17        17           
  Lines            528       526    -2     
===========================================
- Hits             528       526    -2     
Impacted Files Coverage Ξ”
src/Parser.php 100.00% <100.00%> (ΓΈ)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov-commenter avatar Oct 03 '22 19:10 codecov-commenter

Thanks for finding the time to review and merge the PR! Do you reckon this fix can be tagged as 1.1.3? :)

cerbero90 avatar Oct 11 '22 21:10 cerbero90

Sure. I was just waiting for your response and maybe for #78 's as well.

halaxa avatar Oct 12 '22 11:10 halaxa