Bug 10131

Summary: System preference search doesn't work for search terms starting with *
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: System AdministrationAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact:
Severity: trivial    
Priority: P5 - low CC: chris, gmcharlt, mtompset, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 10131: Add a fallback if the pref search is not a valid regex
Bug 10131: Add a fallback if the pref search is not a valid regex
Bug 10131: Add a fallback if the pref search is not a valid regex
[PASSED QA] Bug 10131: Add a fallback if the pref search is not a valid regex

Description Katrin Fischer 2013-04-26 14:59:07 UTC
If you try searching for a system preference with something like *black* you will get an ugly error message:

Software error:

Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE notes/ at /usr/share/koha/intranet/cgi-bin/admin/preferences.pl line 255.
Comment 1 Jonathan Druart 2015-04-14 11:49:38 UTC Comment hidden (obsolete)
Comment 2 Mark Tompsett 2015-04-14 13:09:27 UTC
(In reply to Jonathan Druart from comment #1)
> 1/ Search for sysprefs with "notes.*", note the number of results
> 2/ Search for *notes*, boom
> 3/ Apply the patch
> 4/ Repeat 1 and confirm you get the same number of results
> 5/ Repeat 2 and confirm you don't get the error anymore

Actually, I've tried:
black     -- works (1 result)
black.*   -- works (1 result)
.*black   -- works (1 result)
.*black.* -- works (1 result)
black*    -- works (1 result)
*black    -- runs  (0 results)
*black*   -- runs  (0 results)

Perl 5.18.2 on Ubuntu 14.04 if that matters.
Why the two with 0 results?
Comment 3 Mark Tompsett 2015-04-14 13:11:29 UTC
Since bugzilla didn't tell me that Jonathan got my question, and since he provided the patch, I changed the bug so he is the assigned person.
Comment 4 Jonathan Druart 2015-04-14 13:25:15 UTC
(In reply to M. Tompsett from comment #2)
> (In reply to Jonathan Druart from comment #1)
> > 1/ Search for sysprefs with "notes.*", note the number of results
> > 2/ Search for *notes*, boom
> > 3/ Apply the patch
> > 4/ Repeat 1 and confirm you get the same number of results
> > 5/ Repeat 2 and confirm you don't get the error anymore
> 
> Actually, I've tried:
> black     -- works (1 result)
> black.*   -- works (1 result)
> .*black   -- works (1 result)
> .*black.* -- works (1 result)
> black*    -- works (1 result)
> *black    -- runs  (0 results)
> *black*   -- runs  (0 results)
> 
> Perl 5.18.2 on Ubuntu 14.04 if that matters.
> Why the two with 0 results?

Because it's not a well formatted regex.
Comment 5 Mark Tompsett 2015-04-14 14:49:08 UTC Comment hidden (obsolete)
Comment 6 Mark Tompsett 2015-04-14 14:50:12 UTC Comment hidden (obsolete)
Comment 7 Katrin Fischer 2015-04-15 20:42:40 UTC
Created attachment 37920 [details] [review]
[PASSED QA] Bug 10131: Add a fallback if the pref search is not a valid regex

It's possible to search prefs using a regex.
But it the regex is not correctly written, the app explodes.
We should provide a fallback.

Test plan:
0/ Does not apply the patch
1/ Search for sysprefs with "notes.*", note the number of results
2/ Search for *notes*, boom
3/ Apply the patch
4/ Repeat 1 and confirm you get the same number of results
5/ Repeat 2 and confirm you don't get the error anymore

NOTE: As noted on comment #4, the kaboom is because of the
      leading * and not the following *, because 's*' is a valid
      regular expression, while '*n' is not.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 8 Tomás Cohen Arazi (tcohen) 2015-04-21 16:55:57 UTC
Patch pushed to master.

Thanks Jonathan!
Comment 9 Chris Cormack 2015-04-22 05:52:19 UTC
Pushed to 3.18.x will be in 3.18.6