Bugzilla – Attachment 140636 Details for
Bug 31565
Patron search filter by category code with special character returns no results
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31565: Fix datatables searching escape for exact search
Bug-31565-Fix-datatables-searching-escape-for-exac.patch (text/plain), 3.33 KB, created by
Lari Taskula
on 2022-09-14 14:38:02 UTC
(
hide
)
Description:
Bug 31565: Fix datatables searching escape for exact search
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2022-09-14 14:38:02 UTC
Size:
3.33 KB
patch
obsolete
>From a1ea025f06c607b4746d04bd4dc96ead80141e7f Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 14 Sep 2022 14:34:48 +0000 >Subject: [PATCH] Bug 31565: Fix datatables searching escape for exact search > >To test: >1. Add a new patron category with categorycode 'TEST_CAT' >2. Add a patron to category 'TEST_CAT' >3. Go to Patrons search view >4. Under "Search for patron" filters, filter by category you created at step 1 >5. Click Search >6. Observe no results >7. Go to the cities page >8. Add two cities: > - 'Cordoba %' > - 'Buenos Aires _' > - 'London \' >9. Use the column search on the name, alternating _, \ and % as the query >=> FAIL: Weird behavior >10. Apply this patch and reload >11. Repeat 9 >=> SUCCESS: Filtering works correctly! >12. Repeat 3-5 >13. Observe expected result >--- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index f6b079c794..68794261a5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -579,7 +579,9 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > function build_query(col, value){ > > // escape SQL special characters >- value = value.replace(/(\%|\_|\\)/g, "\\$1" ); >+ value_escaped = value.replace(/\\/g, "\\$1" ); >+ // escape SQL LIKE special characters >+ value_like_escaped = value.replace(/(\%|\_|\\)/g, "\\$1"); > > var parts = []; > var attributes = col.data.split(':'); >@@ -587,13 +589,13 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { > var part = {}; > var attr = attributes[i]; > let criteria = options.criteria; >- if ( value.match(/^\^(.*)\$$/) ) { >- value = value.replace(/^\^/, '').replace(/\$$/, ''); >+ if ( value_escaped.match(/^\^(.*)\$$/) ) { >+ value_escaped = value_escaped.replace(/^\^/, '').replace(/\$$/, ''); > criteria = "exact"; > } > part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' >- ? value >- : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; >+ ? value_escaped >+ : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value_like_escaped + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; > parts.push(part); > } > return parts; >-- >2.25.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 31565
:
140636
|
140637
|
140709
|
140753
|
140754
|
140755
|
140756
|
140757
|
140758
|
140978
|
140984
|
142861