From 152171006218a1ecfbaf567c8e20ce854d09c613 Mon Sep 17 00:00:00 2001 From: tetragon Date: Thu, 18 Oct 2007 23:00:16 +0000 Subject: Some template handling tweaking to allow for escaping scalar references git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1788 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template/CSV.pm | 12 ++++++++++-- LedgerSMB/Template/HTML.pm | 6 ++++++ LedgerSMB/Template/LaTeX.pm | 16 ++++++++++++---- LedgerSMB/Template/ODS.pm | 3 +++ LedgerSMB/Template/TXT.pm | 3 +++ LedgerSMB/Template/XLS.pm | 8 +++++++- 6 files changed, 41 insertions(+), 7 deletions(-) (limited to 'LedgerSMB/Template') diff --git a/LedgerSMB/Template/CSV.pm b/LedgerSMB/Template/CSV.pm index 9700a18a..50edef15 100755 --- a/LedgerSMB/Template/CSV.pm +++ b/LedgerSMB/Template/CSV.pm @@ -38,6 +38,9 @@ holders, see the CONTRIBUTORS file. package LedgerSMB::Template::CSV; +use warnings; +use strict; + use Error qw(:try); use Template; use LedgerSMB::Template::TTI18N; @@ -54,12 +57,17 @@ sub preprocess { #XXX fix escaping function return $rawvars if $type =~ /^LedgerSMB::Locale/; + return unless defined $rawvars; if ( $type eq 'ARRAY' ) { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } - } elsif ( !$type ) { # Scalar - $vars = $rawvars; + } elsif ( !$type or $type eq 'SCALAR' ) { # Scalar + if ($type eq 'SCALAR' ) { + $vars = $$rawvars; + } else { + $vars = $rawvars; + } $vars =~ s/(^ +| +$)//g; $vars =~ s/"/""/g; $vars = qq|"$vars"| if $vars !~ /^\w*$/; diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index 340b6c94..9159098e 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -39,6 +39,9 @@ holders, see the CONTRIBUTORS file. package LedgerSMB::Template::HTML; +use warnings; +use strict; + use Error qw(:try); use CGI::Simple::Standard qw(:html); use Template; @@ -56,12 +59,15 @@ sub preprocess { #XXX fix escaping function return $rawvars if $type =~ /^LedgerSMB::Locale/; + return unless defined $rawvars; if ( $type eq 'ARRAY' ) { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } } elsif (!$type) { return escapeHTML($rawvars); + } elsif ($type eq 'SCALAR') { + return escapeHTML($$rawvars); } else { # Hashes and objects for ( keys %{$rawvars} ) { $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); diff --git a/LedgerSMB/Template/LaTeX.pm b/LedgerSMB/Template/LaTeX.pm index 06c4b8c4..973cb724 100755 --- a/LedgerSMB/Template/LaTeX.pm +++ b/LedgerSMB/Template/LaTeX.pm @@ -47,6 +47,9 @@ holders, see the CONTRIBUTORS file. package LedgerSMB::Template::LaTeX; +use warnings; +use strict; + use Error qw(:try); use Template::Latex; use LedgerSMB::Template::TTI18N; @@ -62,15 +65,20 @@ sub preprocess { my $type = ref $rawvars; return $rawvars if $type =~ /^LedgerSMB::Locale/; + return unless defined $type; if ($type eq 'ARRAY') { for (@{$rawvars}) { push @{$vars}, preprocess($_); } - } elsif (!$type) { + } elsif (!$type or $type eq 'SCALAR') { + if ($type eq 'SCALAR') { + $vars = $$rawvars; + } else { + $vars = $rawvars; + } #XXX Fix escaping - $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; - $rawvars =~ s/"(.*)"/``$1''/gs; - return $rawvars; + $vars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; + $vars =~ s/"(.*)"/``$1''/gs; } else { for ( keys %{$rawvars} ) { $vars->{$_} = preprocess($rawvars->{$_}); diff --git a/LedgerSMB/Template/ODS.pm b/LedgerSMB/Template/ODS.pm index 08df87a7..f3a37583 100644 --- a/LedgerSMB/Template/ODS.pm +++ b/LedgerSMB/Template/ODS.pm @@ -800,12 +800,15 @@ sub preprocess { #XXX fix escaping function return $rawvars if $type =~ /^LedgerSMB::Locale/; + return unless defined $rawvars; if ( $type eq 'ARRAY' ) { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } } elsif (!$type) { return escapeHTML($rawvars); + } elsif ($type eq 'SCALAR') { + return escapeHTML($$rawvars); } else { # Hashes and objects for ( keys %{$rawvars} ) { $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); diff --git a/LedgerSMB/Template/TXT.pm b/LedgerSMB/Template/TXT.pm index d6fa3e4b..66169613 100755 --- a/LedgerSMB/Template/TXT.pm +++ b/LedgerSMB/Template/TXT.pm @@ -38,6 +38,9 @@ holders, see the CONTRIBUTORS file. package LedgerSMB::Template::TXT; +use warnings; +use strict; + use Error qw(:try); use Template; use LedgerSMB::Template::TTI18N; diff --git a/LedgerSMB/Template/XLS.pm b/LedgerSMB/Template/XLS.pm index 5e03c7c9..acb8196e 100644 --- a/LedgerSMB/Template/XLS.pm +++ b/LedgerSMB/Template/XLS.pm @@ -48,6 +48,9 @@ holders, see the CONTRIBUTORS file. package LedgerSMB::Template::XLS; +use warnings; +use strict; + use Error qw(:try); use CGI::Simple::Standard qw(:html); use Excel::Template::Plus; @@ -65,12 +68,15 @@ sub preprocess { #XXX fix escaping function return $rawvars if $type =~ /^LedgerSMB::Locale/; + return $rawvars unless defined $rawvars; if ( $type eq 'ARRAY' ) { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } } elsif (!$type) { return escapeHTML($rawvars); + } elsif ($type eq 'SCALAR') { + return escapeHTML($$rawvars); } else { # Hashes and objects for ( keys %{$rawvars} ) { $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); @@ -110,7 +116,7 @@ sub process { ); $template->write_file("$parent->{outputfile}.xls"); - parent->{mimetype} = 'application/vnd.ms-excel'; + $parent->{mimetype} = 'application/vnd.ms-excel'; } sub postprocess { -- cgit v1.2.3