From 77c2dbd594683ab0dd2aec62358c57dda9906186 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Thu, 16 Aug 2012 16:57:29 +0200 Subject: [PATCH] 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 Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack (cherry picked from commit 3e599787d4a3b918f45914347344f4a1d99241c2) Signed-off-by: Jared Camins-Esakov --- koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt | 5 +++++ koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt | 5 +++++ koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index d05eab2c2a..e01acdd22d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -88,6 +88,11 @@ $(".addtocart").show(); [% 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();}); diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt index 9e1b8553f3..2d52b33768 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt @@ -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();}); diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index b3f23d0b92..defc64b6b6 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -200,6 +200,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 %] -- 2.39.5