fix(web): escape search text in the link memo filter (#6583)

This commit is contained in:
Divya
2026-11-18 05:46:11 -08:00
committed by GitHub
parent 5e4bfcd008
commit 43a3feca7a
2 changed files with 39 additions and 1 deletions
@@ -50,7 +50,7 @@ export const useLinkMemo = ({ isOpen, currentMemoName, existingRelations, onAddR
conditions.push(creatorFilter);
}
if (searchText) {
conditions.push(`content.contains("${searchText}")`);
conditions.push(`content.contains(${JSON.stringify(searchText)})`);
}
const { memos } = await memoServiceClient.listMemos({
pageSize: DEFAULT_LIST_MEMOS_PAGE_SIZE,
+38
View File
@@ -0,0 +1,38 @@
import { act, renderHook, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
listMemos: vi.fn(),
}));
vi.mock("@/connect", () => ({
memoServiceClient: { listMemos: mocks.listMemos },
}));
vi.mock("@/hooks/useCurrentUser", () => ({
default: () => ({ name: "users/alice" }),
}));
import { useLinkMemo } from "@/components/MemoEditor/edit/hooks/useLinkMemo";
const lastFilter = () => mocks.listMemos.mock.calls.at(-1)?.[0]?.filter;
describe("useLinkMemo search filter", () => {
beforeEach(() => {
mocks.listMemos.mockResolvedValue({ memos: [] });
});
it.each([
["meeting", 'creator == "users/alice" && content.contains("meeting")'],
['say "hi"', 'creator == "users/alice" && content.contains("say \\"hi\\"")'],
["C:\\", 'creator == "users/alice" && content.contains("C:\\\\")'],
])("passes %j to the filter as a quoted CEL string", async (searchText, expected) => {
const { result } = renderHook(() => useLinkMemo({ isOpen: true, existingRelations: [], onAddRelation: vi.fn() }));
act(() => {
result.current.setSearchText(searchText);
});
await waitFor(() => expect(lastFilter()).toBe(expected));
});
});