The best way to control Claude Code, Codex and more from any computer or phone
fix(server): an invalid regex in project search still finds its text when Match case is off (#30569)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
MarcoDotIO committed
Nov 5, 2026 at 23:33 UTC
d1667e833c81b62ed76dabf783e7c501888f987e
2 files changed
+39
-2
apps/server/src/workspace/WorkspaceEntries.test.ts
+26
@@ -672,6 +672,32 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
672
}),
673
);
674
675
+ it.effect("searches an invalid regex literally without matching case", () =>
676
+ Effect.gen(function* () {
677
+ const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-invalid-regex-" });
678
+ yield* writeTextFile(cwd, "src/calls.ts", "call(Foo(bar));\n");
679
+
680
+ const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
681
+ const result = yield* workspaceEntries.searchContents({
682
+ cwd,
683
+ query: "foo(",
684
+ limit: 100,
685
+ caseSensitive: false,
686
+ wholeWord: false,
687
+ useRegex: true,
688
+ });
689
+
690
+ expect(result.regexFallbackError).toBeDefined();
691
+ expect(result.matches).toEqual([
692
+ expect.objectContaining({
693
+ path: "src/calls.ts",
694
+ lineNumber: 1,
695
+ matchRanges: [{ start: 5, end: 9 }],
696
+ }),
697
+ ]);
698
+ }),
699
+ );
700
+
701
it.effect("maps multi-byte lines to string-indexed ranges", () =>
702
Effect.gen(function* () {
703
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-content-multibyte-" });
apps/server/src/workspace/WorkspaceSearchIndex.ts
+13
-2
@@ -478,7 +478,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
478
const searchContents: WorkspaceSearchIndex["Service"]["searchContents"] = Effect.fn(
479
"WorkspaceSearchIndex.searchContents",
480
)(function* (input) {
481
- const { searchQuery, regexMode } = buildContentSearchQuery(input);
481
+ let { searchQuery, regexMode } = buildContentSearchQuery(input);
482
const deadline = performance.now() + CONTENT_SEARCH_TIME_BUDGET_MS;
483
// Grep cursors advance per file; whole-word filtering needs enough raw candidates before advancing.
484
const rawPageSize = input.wholeWord
@@ -487,6 +487,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
487
const matches: Array<ProjectSearchContentsResult["matches"][number]> = [];
488
let nextCursor: GrepCursor | null = null;
489
let regexFallbackError: string | undefined;
490
+ let retryLiterally = false;
491
492
do {
493
const remainingTimeBudgetMs = Math.max(1, Math.ceil(deadline - performance.now()));
@@ -500,6 +501,13 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
501
timeBudgetMs: remainingTimeBudgetMs,
502
}),
503
);
504
+ // fff searches an invalid pattern as a literal, which would keep the `(?i)` prefix.
505
+ retryLiterally = regexMode && !input.caseSensitive && result.regexFallbackError !== undefined;
506
+ if (retryLiterally) {
507
+ regexFallbackError = result.regexFallbackError;
508
+ ({ searchQuery, regexMode } = buildContentSearchQuery({ ...input, useRegex: false }));
509
+ continue;
510
+ }
511
512
for (const match of result.items) {
513
const matchRanges = mapContentMatchRanges(match.lineContent, match.matchRanges).filter(
@@ -516,7 +524,10 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
524
}
525
nextCursor = result.nextCursor;
526
regexFallbackError ??= result.regexFallbackError;
519
- } while (matches.length < input.limit && nextCursor !== null && performance.now() < deadline);
527
+ } while (
528
+ retryLiterally ||
529
+ (matches.length < input.limit && nextCursor !== null && performance.now() < deadline)
530
+ );
531
532
return {
533
matches: matches.slice(0, input.limit),