Bug 40907: Prevent DT crash when searching with regex metachars

We should remove the regex metacharacters from the string or JS code
will raise an error and the query won't be generated, leading to the DT
neverending loading problem.

Test plan:
Go to http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=4
In the global "Search" of the items table, search using a regex
metacharacters in order to form a broken regex (eg. '[')
=> Without this patch there is a JS error in the console "Uncaught
SyntaxError: unterminated character class" and you get the "Processing"
that never ends
=> With this patch applied the search succeeds.

Signed-off-by: Mathieu <mathsabypro@gmail.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 0f6f5ab252)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-10-07 14:48:09 +02:00 committed by Paul Derscheid
parent 000ba6efdd
commit c338abe8c3
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 7 additions and 1 deletions

View File

@ -555,8 +555,14 @@ function _dt_default_ajax(params) {
const search_value = value.length
? value
: global_search;
// Escape all regex metachars . * + ? ^ $ { } ( ) | [ ] \
const regex = new RegExp(
`^${search_value}`,
"^" +
search_value.replace(
/[.*+?^${}()|[\]\\]/g,
"\\$&"
),
"i"
);
if (