Skip to content

Commit

Permalink
fix: escape regex input (#864)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

# Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: IN-929

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

## Does this introduce a breaking change?

- [ ] Yes
- [ ] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->
  • Loading branch information
kodiakhq[bot] authored Oct 26, 2023
2 parents 47ccf88 + 076dcf1 commit 9de39a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/ui/components/core/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@mantine/core'
import { useForm } from '@mantine/form'
import { useDebouncedValue } from '@mantine/hooks'
import regexEscape from 'escape-string-regexp'
import { localeIncludes } from 'locale-includes'
import { useRouter } from 'next/router'
import { Trans, useTranslation } from 'next-i18next'
Expand Down Expand Up @@ -253,7 +254,7 @@ export const SearchBox = ({
) satisfies Partial<AutocompleteProps>

const matchText = (result: string, textToMatch: string) => {
const matcher = new RegExp(`(${textToMatch})`, 'ig')
const matcher = new RegExp(`(${regexEscape(textToMatch)})`, 'ig')
const replaced = reactStringReplace(result, matcher, (match, i) => (
<span key={i} className={classes.matchedText}>
{match}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ajv": "8.12.0",
"alex": "11.0.1",
"cookies-next": "4.0.0",
"escape-string-regexp": "5.0.0",
"geolib": "3.3.4",
"json-schema-to-zod": "1.1.1",
"just-compact": "3.2.0",
Expand Down
33 changes: 26 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9de39a6

Please sign in to comment.