fix: fetch() validation hardening — named args, string-keyed arrays (closes #205, refs #206) - #208
Merged
Merged
Conversation
…loses #205, refs #206) - Guard is_array($args[0]) with isset(): fetch(pks: [...]) no longer emits 'Undefined array key 0' before the ZVecException (#205) - Named-arg pks: rejected in all forms, including next to a positional array (previously silently ignored) - Mixing scalar PKs with an outputFields array now throws a calling-convention hint (#206 DX part) - toCStringArray(): reindex with array_values() and reject non-string elements — string-keyed arrays previously corrupted memory and segfaulted (protects all FFI string-array call sites) - Unknown named arguments throw with a hint instead of segfaulting; outputFields: now supported as a named argument in both forms - Add tests/test_fetch_validation.phpt; update CHANGELOG + README
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #205, refs #206 (DX part)
Hardens
ZVecCollection::fetch()argument validation: the reportedUndefined array key 0warning is gone and named-argument calls get clearZVecExceptionmessages instead of confusing errors, silent misbehavior or native segfaults found during code review.Changes
is_array($args[0])withisset()sofetch(pks: ['doc1'])no longer emits a PHP warning before the validation error (bug: fetch(pks: [...]) emits "Undefined array key 0" warning before rejecting #205)pks:rejected with a calling-convention hint in all forms, including next to a positional array (previously silently ignored)fetch('doc1', ['name'])(scalar PK + outputFields array) now throws a hint to usefetch(['doc1'], ['name'])(enhancement: fetch() mixing scalar PK and outputFields array fails with confusing "PKs must be non-empty strings" #206 DX part)toCStringArray(): reindexes witharray_values()and rejects non-string elements — string-keyed arrays previously corrupted memory and segfaulted (protects all FFI string-array call sites)fetch('pk1', foo: 'bar')) throw with a hint instead of segfaultingoutputFields:accepted as a named argument in both forms (previously silently ignored)Testing
tests/test_fetch_validation.phptpasses (rejections + no-warning assertions + string-keyed/named-arg forms)php run-tests.php -n tests/→ 178 passed, 1 known environmental failure (test_collections_thread_safety.phpt— macOS FD limit 256, pre-existing on main, passes on Linux CI)test_dbs/empty)Code Review
fetch([1 => ['name']])returns empty result) left as follow-up candidateFollow-up candidates (not part of this PR)
fetch([1 => ['name']])(single array argument at non-zero spread key) returns an empty result instead of erroring — exotic input, no crashfetch('doc1', ['name'])outright (this PR only improves the error message)