Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export const matcher = ({ option, searchTerm = '', searchIndices }) => {
}
if (searchIndices) {
return makeArray(searchIndices).some(index => {
return (option[index] || '').toLowerCase().indexOf(searchTerm) !== -1;
if (typeof (option[index] || '') === 'string') {
return (option[index] || '').toLowerCase().indexOf(searchTerm) !== -1;
}
return (String(option[index]) || '').toLowerCase().indexOf(searchTerm) !== -1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(1) => "1"
String(null) => "null"
String(undefined) => "undefined"

@SCasarotto While stringifying the number is fine; null & undefined values shouldn't be part of search. We can exclude them. Something like

//...
    return makeArray(searchIndices).some(index => {
      let value = option[index];
      return !isNone(value) && String(value).toLowerCase().indexOf(searchTerm) !== -1;
    });
//...

export const isNone = value => value === null || value === undefined;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SCasarotto It would be great if you could also add unit tests for the matcher func under src/__tests__/utils-test.js. Possible ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to try to add some tests and update the code as you suggested. I am not sure when I will be able to fit this in though.

});
}
return true;
Expand Down