Skip to content

Commit

Permalink
fix(search): search with whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Oct 31, 2024
1 parent aa2d989 commit 36f0971
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/features/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default function search(items, pattern, options) {
keys
} = options;

// drop leading and trailing whitespace
pattern = pattern.trim();

return items.flatMap((item, idx) => {
const tokens = getTokens(item, pattern, keys);

Expand Down
21 changes: 21 additions & 0 deletions test/spec/features/search/searchSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ describe('search', function() {
expect(results[1].item).to.eql(items[1]);
}));


it('should search with whitespace', inject(function(search) {

// given
const items = [
{
title: 'bar foo bar'
}
];

// when
const results = search(items, ' foo bar ', {
keys: [
'title'
]
});

// then
expect(results).to.have.length(1);
}));

});


Expand Down

0 comments on commit 36f0971

Please sign in to comment.