Skip to content

Fix JsonPointer::remove() not handling sequential arrays correctly #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

outdooracorn
Copy link
Contributor

The JsonPointer::remove() method doesn't correctly detect sequential vs associative arrays when the TOLERATE_ASSOCIATIVE_ARRAYS is enabled. This causes most sequential arrays to be converted to associative arrays.

The issue is due to the $i counter not being incremented in the foreach loop that detects whether an array is sequential or associative.

While the counter can be incremented in the if statement, like in #65, I've decided to do it in the body of the foreach loop as I believe it to be less "clever" and easier to read. I have also added a test to prove the issue and defend against it in the future.

Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #67 (236de58) into master (f4e5117) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 236de58 differs from pull request most recent head 22c33af. Consider uploading reports for the commit 22c33af to get more accurate results

@@           Coverage Diff           @@
##           master      #67   +/-   ##
=======================================
  Coverage   96.95%   96.96%           
=======================================
  Files          15       15           
  Lines         592      593    +1     
=======================================
+ Hits          574      575    +1     
  Misses         18       18           
Files Coverage Δ
src/JsonPointer.php 94.92% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@outdooracorn
Copy link
Contributor Author

Hey @vearutop, any chance you're able to find some time to merge this PR? We would love to get the fix pushed out to production as soon as possible. Thanks

@vearutop
Copy link
Member

Ah, sorry this took me so long. Thank you for you contribution!

@vearutop vearutop merged commit 17bfc66 into swaggest:master Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants