fix(web): escape prompt editor typeahead query before building RegExp - #38416
Open
manan-tech wants to merge 1 commit into
Open
fix(web): escape prompt editor typeahead query before building RegExp#38416manan-tech wants to merge 1 commit into
manan-tech wants to merge 1 commit into
Conversation
The `{`-triggered component picker builds `new RegExp(queryString, 'i')`
from arbitrary prompt text. Text such as `[Open manual]({source_url})`
makes the query string `source_url})`, which is invalid regex syntax and
throws during render, crashing the prompt editor.
Escape the query string before constructing the RegExp so user-entered
text is matched literally instead of being interpreted as a pattern.
Applies to both `useVariableOptions` and `useExternalToolOptions`.
Fixes langgenius#38384
manan-tech
requested review from
CodingOnStar,
hyoban,
iamjoel and
zxhlyh
as code owners
July 4, 2026 11:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38384
Summary
The
{-triggered component picker in the prompt editor builds a regular expression directly from the typeahead query string:The query string is arbitrary prompt text that follows a
{. A common prompt such as:makes the query string
source_url}), which is invalid regex syntax (Unmatched ")").new RegExpthrows aSyntaxErrorduring render, and the whole prompt editor crashes with an unexpected component rendering error. Other characters such as[(unterminated character class) or a trailing\fail the same way.Fix
Escape the query string before constructing the
RegExp, using the same inlineescapeRegExpidiom already used elsewhere in the codebase (goto-anything,agent-v2,console-openapi-url):This is applied at both call sites (
useVariableOptionsanduseExternalToolOptions). As a side benefit, the typeahead now matches the query literally instead of interpreting user-typed text as a regex pattern, which is the expected behavior when filtering variable / tool names.Testing
Added regression tests to the existing
component-picker-block/__tests__/hooks.spec.tsx:Crash-guard cases (
source_url}),a[b, trailing\) for bothuseVariableOptionsanduseExternalToolOptions— verified these fail on the unescaped code (exactSyntaxError) and pass with the fix.A literal-match assertion confirming
a.bmatches onlya.b, notaxb.pnpm teston the spec: 67/67 passpnpm eslinton changed files: 0 errorspnpm type-check: passes