Bug 8646 - prevent the highlighter from going infinite loop
authorRobin Sheat <robin@catalyst.net.nz>
Thu, 16 Aug 2012 14:57:29 +0000 (16:57 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 31 Aug 2012 21:34:28 +0000 (23:34 +0200)
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>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt

index 09c946e..2e71ba7 100644 (file)
@@ -96,6 +96,11 @@ $(".addtocart").show();
     toHighlight = $("p,span.results_summary,a.title");
         var query_desc = "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
         q_array = query_desc.split(" ");
+        // ensure that we don't have "" at the end of the array, which can
+        // break the highlighter
+        while (q_array.length > 0 && q_array[q_array.length-1] == "") {
+            q_array = q_array.splice(0,-1);
+        }
         highlightOn();
         $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
         $("#highlight_toggle_off").show().click(function() {highlightOff();});
index bbdd618..ef2ca72 100644 (file)
@@ -58,6 +58,11 @@ $(document).ready(function(){
     [% IF ( query_desc ) %]
     var query_desc = "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
     q_array = query_desc.split(" ");
+    // ensure that we don't have "" at the end of the array, which can
+    // break the highlighter
+    while (q_array.length > 0 && q_array[q_array.length-1] == "") {
+        q_array = q_array.splice(0,-1);
+    }
     highlightOn();
     $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
     $("#highlight_toggle_off").show().click(function() {highlightOff();});
index 81f825a..3f8e6d3 100644 (file)
@@ -203,6 +203,11 @@ $(document).ready(function(){
 
 [% IF ( query_desc ) %][% IF ( OpacHighlightedWords ) %]var query_desc = "[% query_desc |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]";
         q_array = query_desc.split(" ");
+        // ensure that we don't have "" at the end of the array, which can
+        // break the highlighter
+        while (q_array.length > 0 && q_array[q_array.length-1] == "") {
+            q_array = q_array.splice(0,-1);
+        }
         highlightOn();
         $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
         $("#highlight_toggle_off").show().click(function() {highlightOff();});[% END %][% END %]