Bugzilla – Attachment 187524 Details for
Bug 40907
parenthesis and bracket are breaking filter on item table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40907: Prevent DT crash when searching with regex metachars
Bug-40907-Prevent-DT-crash-when-searching-with-reg.patch (text/plain), 1.98 KB, created by
Jonathan Druart
on 2025-10-07 12:54:59 UTC
(
hide
)
Description:
Bug 40907: Prevent DT crash when searching with regex metachars
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-10-07 12:54:59 UTC
Size:
1.98 KB
patch
obsolete
>From 045109b2a7a0255d8cc86938fae47cf807e3efc9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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. >--- > 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 3af04d2a160..fb8e6792a1f 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 ( >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40907
:
187523
|
187524
|
187534
|
187535
|
187536
|
187599
|
187600
|
188022
|
188023