Skip to content

Commit

Permalink
Item13897: Fixed cloning of non-HASH blessed objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Dec 16, 2016
1 parent eb65efc commit ed07442
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/lib/Foswiki/Object.pm
Expand Up @@ -22,7 +22,7 @@ features.
require Carp;
require Foswiki::Exception;
use Try::Tiny;
use Scalar::Util qw(blessed refaddr weaken isweak);
use Scalar::Util qw(blessed refaddr reftype weaken isweak);

use Foswiki::Class;

Expand Down Expand Up @@ -241,8 +241,24 @@ sub _cloneData {
# cloning as a hash and blessing the resulting hashref into
# $val's class.
# SMELL Pretty much unreliable for complex classes.
$cloned =
$this->_cloneData( {%$val}, "$attr.blessed($class)" );
my $reftype = reftype($val);
if ( $reftype eq 'HASH' ) {
$cloned =
$this->_cloneData( {%$val}, "$attr.blessed($class)" );
}
elsif ( $reftype eq 'ARRAY' ) {
$cloned =
$this->_cloneData( [@$val], "$attr.blessed($class)" );
}
elsif ( $reftype eq 'SCALAR' ) {
$cloned =
$this->_cloneData( \$$val, "$attr.blessed($class)" );
}
else {
# Cannot clone unknown datatypes, just copy the original
# ref.
$cloned = $val;
}
bless $cloned, ref($val)
if $cloned != $val;
}
Expand Down

0 comments on commit ed07442

Please sign in to comment.