From 19987b53b42de3a1894702f4d358fcfffddc4b32 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 2 Aug 2008 22:47:15 +0000 Subject: [PATCH] Fix Stow to always return safe copies of stowed data. And test it. --- lib/WebGUI/Session/Stow.pm | 12 ++++++++++++ t/Session/Stow.t | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/WebGUI/Session/Stow.pm b/lib/WebGUI/Session/Stow.pm index ef6efd84f..b9717f697 100644 --- a/lib/WebGUI/Session/Stow.pm +++ b/lib/WebGUI/Session/Stow.pm @@ -109,6 +109,18 @@ sub get { my $self = shift; my $var = shift; return undef if $self->session->config->get("disableCache"); + my $ref = $self->{_data}{$var}; + if (ref $ref eq 'ARRAY') { + my @safeArray = @{ $ref }; + return \@safeArray; + } + elsif (ref $ref eq 'HASH') { + my %safeHash = %{ $ref }; + return \%safeHash; + } + else { + return $ref + } return $self->{_data}{$var}; } diff --git a/t/Session/Stow.t b/t/Session/Stow.t index 0475f0691..2e13d5d82 100644 --- a/t/Session/Stow.t +++ b/t/Session/Stow.t @@ -80,7 +80,7 @@ my $milList = $stow->get("military"); push @{ $milList }, qw/foxtrot echo/; -is_deeply($stow->get("military"), [ @orig_list, qw/foxtrot echo/ ], "modifying fetched list changes stow'ed list because it is a reference"); +is_deeply($stow->get("military"), [ @orig_list ], "modifying fetched list does not change original because it is a safe copy"); is($stow->delete(), undef, 'deleting with no key returns undef'); is($stow->delete('noSuchKey'), undef, 'deleting non-existant variable returns undef');