(#9183) - Fix null pointer exception when searching with index for missing field#9199
Open
brucearctor wants to merge 2 commits intoapache:masterfrom
Open
(#9183) - Fix null pointer exception when searching with index for missing field#9199brucearctor wants to merge 2 commits intoapache:masterfrom
brucearctor wants to merge 2 commits intoapache:masterfrom
Conversation
…for missing field filterInclusiveStart throws a TypeError when collating a key for a document that is missing the indexed field. This commit adds a check to skip documents where the required index key is undefined, matching CouchDB's behavior of excluding such documents from the index.
Member
|
could you please ensure you use the PR template? |
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.
Overview
When performing a
find()query that uses an index, if one of the documents in the database is missing the indexed field,filterInclusiveStartthrows aTypeError: can't convert null to objectfrom insidepouchdb-collate.filterInclusiveStartcallsgetKeyFromDocto extract the indexed key from each document. When a document does not have the indexed field,getKeyFromDocreturnsundefinedfor that field. Thisundefinedvalue is then passed tocollate(), which crashes.This fix adds a guard in
filterInclusiveStartto skip any document whose key isundefined(i.e. the document is missing the indexed field). This matches standard CouchDB behaviour, where documents missing a field are excluded from an index.Testing recommendations
A regression test has been added in
tests/find/test-issues/test.issue9183.js:name), one withoutname$gt: nulland verifies only the document with the field is returnedTypeErrorRun with:
TYPE=find PLUGINS=pouchdb-find GREP=issue9183 npm testRelated Issues or Pull Requests
Fixes #9183
Checklist
docsfolder