mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-09 16:50:28 +03:00
sanitize string before used in regex to prevent crash (#2219)
This commit is contained in:
parent
d8d4bce287
commit
9fe67da98b
4 changed files with 13 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ import {
|
|||
matchQuery,
|
||||
ResultHandler,
|
||||
} from '../utils/AsyncSearch';
|
||||
import { sanitizeForRegex } from '../utils/regex';
|
||||
|
||||
export type UseAsyncSearchOptions = AsyncSearchOption & {
|
||||
matchOptions?: MatchQueryOption;
|
||||
|
|
@ -55,8 +56,8 @@ export const orderSearchItems = <TSearchItem extends object | string | number>(
|
|||
|
||||
// we will consider "_" as word boundary char.
|
||||
// because in more use-cases it is used. (like: emojishortcode)
|
||||
const boundaryRegex = new RegExp(`(\\b|_)${query}`);
|
||||
const perfectBoundaryRegex = new RegExp(`(\\b|_)${query}(\\b|_)`);
|
||||
const boundaryRegex = new RegExp(`(\\b|_)${sanitizeForRegex(query)}`);
|
||||
const perfectBoundaryRegex = new RegExp(`(\\b|_)${sanitizeForRegex(query)}(\\b|_)`);
|
||||
|
||||
orderedItems.sort((i1, i2) => {
|
||||
const str1 = performMatch(getItemStr(i1, query), query, options);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue