Skip to content
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

Add safety check for highlighting where field is undefined #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ABWalters
Copy link

@ABWalters ABWalters commented Jul 24, 2018

Using the following search options:

const opts = {
    query: queryParam,
    fields: ['field1', 'field2'],
    include_docs: true,
    highlighting: true,
  };

If field1 matches the queryParam, but field2 does not exist in the document, then the following exception is thrown:

TypeError: Cannot read property 'replace' of undefined
    at \node_modules\pouchdb-quick-search\lib\index.js:421:23
    at Array.forEach (<anonymous>)
    at \node_modules\pouchdb-quick-search\lib\index.js:418:33
    at Array.forEach (<anonymous>)
    at \node_modules\pouchdb-quick-search\lib\index.js:411:42
    at process._tickCallback (internal/process/next_tick.js:68:7)

Some documents in the database do not have field2.

This small check will allow for search and highlighting with inconsistent DB schema.

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.

1 participant