Skip to content

Commit

Permalink
πŸ› Change from RegEx to String.startsWith for safely check query text
Browse files Browse the repository at this point in the history
Fix #94.
  • Loading branch information
gluons committed Jul 3, 2021
1 parent 58d198f commit 639d338
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/getPossibles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ function getPossibles(dataSource: ReadonlyArray<AddressEntry>, target: Target, q
const newDataSource = dataSource.slice(0); // Prevent mutate the original data source. Clone it!

const key = translateTarget(target);
const pattern = new RegExp(`^${query.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')}`);
const possibles: AddressEntry[] = newDataSource.filter(item => {
return item[key] ? pattern.test(`${item[key]}`) : false;
if (!item[key]) {
return false;
}

return `${item[key]}`.startsWith(query);
});
possibles.sort((a, b) => {
let aSimilarity = calculateSimilarity(query, a);
Expand Down

0 comments on commit 639d338

Please sign in to comment.