From 8b641aca011d4ae738e5b4c327bd2532e1b0ed66 Mon Sep 17 00:00:00 2001 From: tetragon Date: Tue, 11 Sep 2007 15:18:39 +0000 Subject: Fixing hash and object escaping git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1563 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template/CSV.pm | 10 +++++----- LedgerSMB/Template/HTML.pm | 9 ++++----- LedgerSMB/Template/PDF.pm | 10 +++++----- LedgerSMB/Template/PS.pm | 19 +++++++++++++++++-- 4 files changed, 31 insertions(+), 17 deletions(-) (limited to 'LedgerSMB/Template') diff --git a/LedgerSMB/Template/CSV.pm b/LedgerSMB/Template/CSV.pm index 42324a89..cb861e93 100755 --- a/LedgerSMB/Template/CSV.pm +++ b/LedgerSMB/Template/CSV.pm @@ -58,11 +58,7 @@ sub preprocess { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } - } elsif ( $type eq 'HASH' ) { - for ( keys %{$rawvars} ) { - $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); - } - } else { + } elsif ( !$type ) { # Scalar $vars = $rawvars; $vars =~ s/\ / /; $vars =~ s/(\t\n\r )+/ /g; @@ -71,6 +67,10 @@ sub preprocess { $vars =~ s/<.*?>//g; $vars = qq|"$vars"| if $vars !~ /^\w+$/; $vars = '' if $vars =~ /^""$/; + } else { # hashes and objects + for ( keys %{$rawvars} ) { + $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); + } } return $vars; } diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index 2f8ac427..6ec7b833 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -60,15 +60,14 @@ sub preprocess { for (@{$rawvars}) { push @{$vars}, preprocess( $_ ); } - } - elsif ( $type eq 'HASH' ) { + } elsif (!$type) { + return CGI::escapeHTML($rawvars); + } else { # Hashes and objects for ( keys %{$rawvars} ) { $vars->{preprocess($_)} = preprocess( $rawvars->{$_} ); } } - else { - return CGI::escapeHTML($rawvars); - } + return $vars; } diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm index cd244736..9c315d62 100755 --- a/LedgerSMB/Template/PDF.pm +++ b/LedgerSMB/Template/PDF.pm @@ -57,15 +57,15 @@ sub preprocess { for (@{$rawvars}) { push @{$vars}, preprocess($_); } - } elsif ($type eq 'HASH') { - for ( keys %{$rawvars} ) { - $vars->{$_} = preprocess($rawvars->{$_}); - } - } else { + } else (!$type) { #XXX Fix escaping $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; $rawvars =~ s/"(.*)"/``$1''/gs; return $rawvars; + } else { + for ( keys %{$rawvars} ) { + $vars->{$_} = preprocess($rawvars->{$_}); + } } return $vars; } diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm index ac58204d..f8c048d0 100755 --- a/LedgerSMB/Template/PS.pm +++ b/LedgerSMB/Template/PS.pm @@ -51,8 +51,23 @@ sub preprocess { my $rawvars = shift; my $vars; my $type = ref $rawvars; - #XXX fix escaping - return $rawvars; + + return $rawvars if $type =~ /^LedgerSMB::Locale/; + if ($type eq 'ARRAY') { + for (@{$rawvars}) { + push @{$vars}, preprocess($_); + } + } else (!$type) { + #XXX Fix escaping + $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; + $rawvars =~ s/"(.*)"/``$1''/gs; + return $rawvars; + } else { + for ( keys %{$rawvars} ) { + $vars->{$_} = preprocess($rawvars->{$_}); + } + } + return $vars; } sub process { -- cgit v1.2.3