fix(library): avoid invalid regular expression in library search (#2439)

This commit is contained in:
Huang Xin
2025-11-13 20:23:26 +05:30
parent a6444b5b33
commit 65ec5c9842
2 changed files with 17 additions and 2 deletions
@@ -50,7 +50,7 @@ export const useBooksSync = () => {
}
},
SYNC_BOOKS_INTERVAL_SEC * 1000,
{ emitLast: false },
{ emitLast: true },
),
[syncBooks],
);
@@ -4,7 +4,22 @@ import { formatAuthors, formatTitle } from '@/utils/book';
export const createBookFilter = (queryTerm: string | null) => (item: Book) => {
if (!queryTerm) return true;
if (item.deletedAt) return false;
const searchTerm = new RegExp(queryTerm, 'i');
let searchTerm: RegExp;
try {
searchTerm = new RegExp(queryTerm, 'i');
} catch {
const lowerQuery = queryTerm.toLowerCase();
const title = formatTitle(item.title).toLowerCase();
const authors = formatAuthors(item.author).toLowerCase();
return (
title.includes(lowerQuery) ||
authors.includes(lowerQuery) ||
item.format.toLowerCase().includes(lowerQuery) ||
(item.groupName && item.groupName.toLowerCase().includes(lowerQuery)) ||
(item.metadata?.description && item.metadata.description.toLowerCase().includes(lowerQuery))
);
}
const title = formatTitle(item.title);
const authors = formatAuthors(item.author);
return (