Bug 35943

Summary: SQL reports groups/subgroups whose name contains regexp special characters break table filtering
Product: Koha Reporter: Julian Maurice <julian.maurice>
Component: ReportsAssignee: Julian Maurice <julian.maurice>
Status: Pushed to oldstable --- QA Contact: Kyle M Hall (khall) <kyle>
Severity: normal    
Priority: P5 - low CC: dcook, fridolin.somers, kyle, lucas
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,23.11.06,23.05.12
Circulation function:
Attachments: Bug 35943: Fix group/subgroup filtering of saved reports
Bug 35943: Fix group/subgroup filtering of saved reports
Bug 35943: Fix group/subgroup filtering of saved reports

Description Julian Maurice 2024-01-30 14:12:21 UTC
Groups and subgroups filtering uses regular expressions. The filter looks like "^" + name + "$"
The problem is that the special characters in group/subgroup name are not properly escaped, which means that if a name contains "+", "*", or any other regexp special characters, filtering will probably fail.

Another (minor) problem is that we use the name to filter instead of the code. So if we have two groups or two subgroups with the same name, it will show reports from both groups/subgroups. There is no reason to have groups/subgroups with the same name, but it is possible (whereas it's not possible to have different groups/subgroups with the same code), so this should be fixed too.
Comment 1 Julian Maurice 2024-01-30 14:47:17 UTC
Created attachment 161645 [details] [review]
Bug 35943: Fix group/subgroup filtering of saved reports

Use code instead of name for filtering and escape regexp special
characters.

This patch also disables datatables' smart filtering as it is not
recommended to use with regexp filtering

https://datatables.net/reference/api/search()

Test plan:
1. Create a report in a group named "Foo + Bar" and in a subgroup named
   "Baz + Quux"
2. Create other reports in group "Foo + Bar" but in other subgroups, as
   well as in other groups. This is useful to see the effect of
   filtering
3. Go to the saved reports page and verify that navigating between tabs
   have the desired result. Same for the subgroup select
Comment 2 David Nind 2024-02-06 18:04:09 UTC
Created attachment 161793 [details] [review]
Bug 35943: Fix group/subgroup filtering of saved reports

Use code instead of name for filtering and escape regexp special
characters.

This patch also disables datatables' smart filtering as it is not
recommended to use with regexp filtering

https://datatables.net/reference/api/search()

Test plan:
1. Create a report in a group named "Foo + Bar" and in a subgroup named
   "Baz + Quux"
2. Create other reports in group "Foo + Bar" but in other subgroups, as
   well as in other groups. This is useful to see the effect of
   filtering
3. Go to the saved reports page and verify that navigating between tabs
   have the desired result. Same for the subgroup select

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 Kyle M Hall (khall) 2024-03-22 10:59:37 UTC
Created attachment 163694 [details] [review]
Bug 35943: Fix group/subgroup filtering of saved reports

Use code instead of name for filtering and escape regexp special
characters.

This patch also disables datatables' smart filtering as it is not
recommended to use with regexp filtering

https://datatables.net/reference/api/search()

Test plan:
1. Create a report in a group named "Foo + Bar" and in a subgroup named
   "Baz + Quux"
2. Create other reports in group "Foo + Bar" but in other subgroups, as
   well as in other groups. This is useful to see the effect of
   filtering
3. Go to the saved reports page and verify that navigating between tabs
   have the desired result. Same for the subgroup select

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 4 Katrin Fischer 2024-03-22 11:28:35 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 5 Fridolin Somers 2024-05-22 14:22:57 UTC
Pushed to 23.11.x for 23.11.06
Comment 6 Lucas Gass (lukeg) 2024-05-28 15:48:37 UTC
Backported to 23.05.x for upcoming 23.05.12