From 7e74841a9759a8383b5d5f4de2c5b7e930298435 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 6 Oct 2025 10:59:11 +0100 Subject: [PATCH] Ensure that invalid search regexp is correctly highlighted (#28724) GitOrigin-RevId: f122e2ea649d8cbfa984ddad0b7424aa96bd015a --- .../components/codemirror-search-form.tsx | 13 ++----------- .../js/features/source-editor/utils}/regexp.ts | 9 +++++++++ .../js/components/full-project-search-ui.tsx | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) rename services/web/{modules/full-project-search/frontend/js/util => frontend/js/features/source-editor/utils}/regexp.ts (57%) diff --git a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx index 8c9232359c..de677a5f1b 100644 --- a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx +++ b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx @@ -37,6 +37,7 @@ import { debounce } from 'lodash' import { EditorSelection, EditorState } from '@codemirror/state' import { sendSearchEvent } from '@/features/event-tracking/search-events' import { FullProjectSearchButton } from './full-project-search-button' +import { isInvalidRegExp } from '../utils/regexp' const MATCH_COUNT_DEBOUNCE_WAIT = 100 // the amount of ms to wait before counting matches const MAX_MATCH_COUNT = 999 // the maximum number of matches to count @@ -253,8 +254,7 @@ const CodeMirrorSearchForm: FC = () => {
= () => { ) } -function isInvalidRegExp(source: string) { - try { - RegExp(source) - return false - } catch { - return true - } -} - export default CodeMirrorSearchForm const buildPosition = debounce( diff --git a/services/web/modules/full-project-search/frontend/js/util/regexp.ts b/services/web/frontend/js/features/source-editor/utils/regexp.ts similarity index 57% rename from services/web/modules/full-project-search/frontend/js/util/regexp.ts rename to services/web/frontend/js/features/source-editor/utils/regexp.ts index 7795d05911..93dd67265f 100644 --- a/services/web/modules/full-project-search/frontend/js/util/regexp.ts +++ b/services/web/frontend/js/features/source-editor/utils/regexp.ts @@ -5,3 +5,12 @@ export const createRegExp = (searchQuery: SearchQuery) => { return new RegExp(searchQuery.search, flags) } + +export const isInvalidRegExp = (searchQuery: SearchQuery): boolean => { + try { + createRegExp(searchQuery) + return false + } catch { + return true + } +} diff --git a/services/web/modules/full-project-search/frontend/js/components/full-project-search-ui.tsx b/services/web/modules/full-project-search/frontend/js/components/full-project-search-ui.tsx index 2112793ae9..fb25e7042d 100644 --- a/services/web/modules/full-project-search/frontend/js/components/full-project-search-ui.tsx +++ b/services/web/modules/full-project-search/frontend/js/components/full-project-search-ui.tsx @@ -30,7 +30,7 @@ import { FullProjectSearchModifiers } from './full-project-search-modifiers' import { isMac } from '@/shared/utils/os' import { PanelHeading } from '@/shared/components/panel-heading' import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context' -import { createRegExp } from '../util/regexp' +import { createRegExp } from '@/features/source-editor/utils/regexp' import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context' import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path' import { FullProjectSearchResults } from './full-project-search-results'