LP#1923225: fix handling of untruncated display fields in accordion
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 13 Apr 2021 23:05:41 +0000 (16:05 -0700)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 25 May 2021 14:34:04 +0000 (10:34 -0400)
A previous commit used the TT2 "html" filter to escape strings to which the
accordion macro is applied, but which don't get truncated.  But that's
incompatible with display fields, which contain embedded HTML and
therefore shouldn't be escaped in that way.  This commit uses
HTML::Defang on untruncated accordion input instead (which is consistent
with how truncated strings are handled by the same macro).

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/misc_util.tt2

index 064c9b8..5e2e320 100644 (file)
@@ -134,6 +134,12 @@ sub init_ro_object_cache {
         return (grep {$_->shortname eq $sn} @$list)[0];
     };
 
+    # Defang an HTML string
+    $locale_subs->{defang_string} = sub {
+        my $html = shift;
+        return $defang->defang($html);
+    };
+
     # Turns one string into two for long text strings
     $locale_subs->{split_for_accordion} = sub {
         my $html = shift;
index fd7c010..7dd4950 100644 (file)
 [% END -%]
 [% MACRO accordion(str, trunc_length, element) BLOCK;
     IF truncate_contents != 1;
-        str | html;
+        ctx.defang_string(str);
     ELSE;
         UNLESS trunc_length;
             trunc_length = contents_truncate_length || 100;
             END;
             str;
         ELSE;
-            str | html;
+            ctx.defang_string(str);
         END;
     END;
 END; %]