Bugzilla – Attachment 59984 Details for
Bug 13618
Add additional template filter methods and a filter presence test to Koha
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13618: Use a simplified version of Template::Stash::AutoEscaping
Bug-13618-Use-a-simplified-version-of-TemplateStas.patch (text/plain), 4.20 KB, created by
Jonathan Druart
on 2017-02-07 15:49:51 UTC
(
hide
)
Description:
Bug 13618: Use a simplified version of Template::Stash::AutoEscaping
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-02-07 15:49:51 UTC
Size:
4.20 KB
patch
obsolete
>From 20bee9210430e91d6e700a5b99be0213dd8c5443 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 7 Feb 2017 16:37:55 +0100 >Subject: [PATCH] Bug 13618: Use a simplified version of > Template::Stash::AutoEscaping > >Koha::Template::Escape is a simple version of Template::Stash::AutoEscaping >It seems that removing and cleanly some pieces of Template::Stash::AutoEscaping >will bring us a lot of performance boost. >--- > C4/Installer/PerlDependencies.pm | 5 --- > C4/Templates.pm | 4 +- > Koha/Template/Escape.pm | 97 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 99 insertions(+), 7 deletions(-) > create mode 100644 Koha/Template/Escape.pm > >diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm >index 8942f23..4e1f75f 100644 >--- a/C4/Installer/PerlDependencies.pm >+++ b/C4/Installer/PerlDependencies.pm >@@ -852,11 +852,6 @@ our $PERL_DEPS = { > required => 1, > min_ver => '0.28', > }, >- 'Template::Stash::AutoEscaping' => { >- 'usage' => 'Code', >- 'required' => '1', >- 'min_ver' => '0.0303', >- }, > }; > > 1; >diff --git a/C4/Templates.pm b/C4/Templates.pm >index 4db5c64..c2f6afc 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -5,7 +5,7 @@ use warnings; > use Carp; > use CGI qw ( -utf8 ); > use List::MoreUtils qw/ any uniq /; >-use Template::Stash::AutoEscaping; >+use Koha::Template::Escape; > > # Copyright 2009 Chris Cormack and The Koha Dev Team > # >@@ -72,7 +72,7 @@ sub new { > COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', > INCLUDE_PATH => \@includes, > FILTERS => {}, >- STASH => Template::Stash::AutoEscaping->new, >+ STASH => Koha::Template::Escape->new, > ENCODING => 'UTF-8', > } > ) or die Template->error(); >diff --git a/Koha/Template/Escape.pm b/Koha/Template/Escape.pm >new file mode 100644 >index 0000000..86c2e18 >--- /dev/null >+++ b/Koha/Template/Escape.pm >@@ -0,0 +1,97 @@ >+package Koha::Template::Escape; >+ >+# This is largely inspired from Template::Stash::AutoEscaping >+ >+use Modern::Perl; >+ >+use Template::Config; >+use parent ($Template::Config::STASH, 'Class::Data::Inheritable'); >+ >+sub new { >+ my $class = shift; >+ my $self = $class->SUPER::new(@_); >+ return $self; >+} >+ >+sub get_raw_args { >+ my ( $args, $escaped_class ) = @_; >+ my $changed = 0; >+ my @raw_args; >+ for my $v (@{ $args }) { >+ my $new_v; >+ if ( ref $v eq $escaped_class ) { >+ $changed = 1; >+ $new_v = $v->[0]; >+ } elsif (ref $v eq 'ARRAY') { >+ $new_v = get_raw_args($v, $escaped_class); >+ if ($new_v) { >+ $changed = 1; >+ } else { >+ $new_v = $v; >+ } >+ } else { >+ $new_v = $v; >+ } >+ push @raw_args, $new_v; >+ } >+ >+ return unless $changed; >+ return \@raw_args; >+} >+ >+sub get { >+ my ( $self, @args ) = @_; >+ >+ # note: hack for [% hash.${key} %] [% hash.item(key) %] >+ # key expected raw string. >+ if (ref $args[0] eq "ARRAY" && (scalar @{$args[0]} > 2)){ >+ my $changed = get_raw_args($args[0], 'Koha::Template::Escape'); >+ # retry by non-escaped args >+ if ($changed) { >+ $args[0] = $changed; >+ return $self->get(@args); >+ } >+ } >+ >+ my ($var) = $self->SUPER::get(@args); >+ if (ref $args[0] eq "ARRAY") { >+ my $key = $args[0]->[0]; >+ if (grep { $key eq $_ } @{ $self->{ignore_escape} }) { >+ return $var; >+ } >+ } >+ >+ my $ref = ref $var; >+ # string >+ if ((!$ref) and (length($var) > 0)) { >+ return $self->escape($var); >+ } >+ return $var; >+} >+ >+# With %XML => xml_escape subroutine from Mojo >+#our %XML = ( >+# '&' => '&', >+# '<' => '<', >+# '>' => '>', >+# '"' => '"', >+# '\'' => ''' >+#); >+ >+# Without XML => TT html filter and AutoEscaping >+sub escape { >+ my $class = shift; >+ my $text = shift; >+# $text =~ s/([&<>"'])/$XML{$1}/ge; >+ for ($text) { >+ s/&/&/g; >+ s/</</g; >+ s/>/>/g; >+ s/"/"/g; >+ s/'/'/g; >+ } >+ >+ return $text; >+} >+ >+1; >-- >2.9.3
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13618
:
35488
|
35516
|
40480
|
40481
|
40482
|
40483
|
40484
|
40485
|
40487
|
41346
|
41347
|
41348
|
41349
|
41350
|
41351
|
41352
|
41353
|
41354
|
41355
|
41746
|
41747
|
41776
|
42009
|
42054
|
42072
|
42073
|
42075
|
42078
|
42079
|
42087
|
42090
|
42091
|
42092
|
42093
|
42094
|
42095
|
42096
|
42097
|
45141
|
45784
|
45785
|
45788
|
46767
|
46768
|
46769
|
46770
|
46771
|
46772
|
46773
|
46774
|
46775
|
46776
|
46777
|
46778
|
46779
|
46780
|
46781
|
46782
|
46783
|
46784
|
46785
|
46786
|
46787
|
46788
|
46789
|
46790
|
46791
|
46792
|
46793
|
46794
|
46795
|
46796
|
46797
|
46798
|
46799
|
46800
|
46801
|
46802
|
46803
|
46804
|
46805
|
46806
|
46807
|
46808
|
46809
|
46810
|
46811
|
46812
|
46813
|
46814
|
46815
|
46816
|
46817
|
46818
|
46819
|
46820
|
46821
|
46822
|
47425
|
47426
|
47427
|
47428
|
47429
|
47430
|
47431
|
47432
|
47433
|
47434
|
47435
|
47436
|
47437
|
47438
|
47439
|
47440
|
47441
|
47442
|
47443
|
47444
|
47445
|
47446
|
47447
|
47448
|
47449
|
47450
|
47451
|
47452
|
47631
|
59983
|
59984
|
59987
|
77804
|
77805
|
77806
|
77807
|
77808
|
77809
|
77997
|
77998
|
78158
|
78274
|
78415
|
79404
|
79818
|
81183
|
83479
|
83480