Bug 8646

Summary: Certain search terms cause browser "script taking too long" error
Product: Koha Reporter: Robin Sheat <robin>
Component: Staff interfaceAssignee: Robin Sheat <robin>
Status: CLOSED FIXED QA Contact:
Severity: minor    
Priority: P5 - low CC: ago, chris, gmcharlt, jonathan.druart, koha.sekjal, paul.poulain
Version: 3.8   
Hardware: All   
OS: All   
See Also: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=10956
Change sponsored?: Sponsored Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 8646 - prevent the highlighter from going infinite loop
Bug 8646 - prevent the highlighter from going infinite loop

Description Robin Sheat 2012-08-15 14:57:35 UTC
Some search terms, particularly those with space characters and similar non-alpha things at the end, can cause the javascript highlighter to go into an infinite loop which causes an error in the browser.

Search queries such as:
http://koha-intra/cgi-bin/koha/catalogue/search.pl?kw=idx&q=ti:book%20
reproduce this.

Curiously, the OPAC is unaffected by this, however it has similar code processes that mean it may be possible for this to happen there too.
Comment 1 Robin Sheat 2012-08-16 15:03:34 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2012-08-17 12:38:49 UTC
Created attachment 11658 [details] [review]
Bug 8646 - prevent the highlighter from going infinite loop

On certain search queries, for example
http://koha-intra/cgi-bin/koha/catalogue/search.pl?kw=idx&q=ti:book%20
the highlighter starts going into an infinite loop until the browser
decides to kill it.

This patch prevents the bad input going to the highlighter.

It also includes the fix on the OPAC, even though the issue doesn't come
up there. Better to be safe...

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Comment 3 Jonathan Druart 2012-08-17 12:40:08 UTC
Works as expected.

I fixed that (in BibLibre repo) with:
 function highlightOn() {
     var x;
     for (x in q_array) {
-        $("p").highlight(q_array[x]);
+        if ( q_array[x].length > 0 ) {
+            $("p").highlight(q_array[x]);
+        }
     }
     $(".highlight_toggle").toggle();
 }

But your patch looks good too.
Comment 4 Ian Walls 2012-08-17 17:00:48 UTC
Drops empty strings are the end of the array in order to prevent infinite loops.  Template only change in JS.  Marking Passed QA.
Comment 5 Paul Poulain 2012-08-31 21:35:16 UTC
Patch pushed to master
Comment 6 Chris Cormack 2012-09-01 07:58:21 UTC
Pushed to 3.8.x will be in 3.8.5
Comment 7 Robin Sheat 2012-09-06 16:28:37 UTC
*** Bug 8736 has been marked as a duplicate of this bug. ***