Bug 8646 - Certain search terms cause browser "script taking too long" error
Summary: Certain search terms cause browser "script taking too long" error
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: 3.8
Hardware: All All
: P5 - low minor (vote)
Assignee: Robin Sheat
QA Contact:
URL:
Keywords:
: 8736 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-15 14:57 UTC by Robin Sheat
Modified: 2014-11-19 09:43 UTC (History)
6 users (show)

See Also:
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 (3.66 KB, patch)
2012-08-16 15:03 UTC, Robin Sheat
Details | Diff | Splinter Review
Bug 8646 - prevent the highlighter from going infinite loop (3.73 KB, patch)
2012-08-17 12:38 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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. ***