From c338abe8c3ce6bebb38e93bbbd09a3a6892eb34c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Oct 2025 14:48:09 +0200 Subject: [PATCH] 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 Signed-off-by: Brendan Lawlor Signed-off-by: Nick Clemens Signed-off-by: Lucas Gass (cherry picked from commit 0f6f5ab2520df089618170aa04e2db42896abf08) Signed-off-by: Paul Derscheid --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 564dd831d3..a598464fc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -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 (