Skip to content

Commit

Permalink
Item14237: Fixed some leafState handling issues.
Browse files Browse the repository at this point in the history
In particular DataHash now enforces leaf status for a node in undefined
state if the node is being assigned with a non-hash value.

Fixed data loss when assigning a hash value to a branch node.

Fixed mistypes.
  • Loading branch information
vrurg committed Apr 15, 2017
1 parent a9118e0 commit f3e2b71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions core/lib/Foswiki/Config/DataHash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ sub STORE {
# operations too.
if ( !$node->isLeaf && ref($value) eq 'HASH' && !tied(%$value) ) {

$this->tieNode($key);
# Check if the node value is a tied hash already.
my $nVal = $node->value;
unless ( defined($nVal) && ref($nVal) eq 'HASH' && tied(%$nVal) ) {
$this->tieNode($key);
}

my $newHash = $node->value;

Expand All @@ -227,6 +231,9 @@ sub STORE {
}
else {
$node->value($value);

# Mark node as leaf if
$node->setLeafState(1) if $node->isVague;
}
}

Expand Down Expand Up @@ -339,7 +346,7 @@ sub getKeyObject {
# here because this is what this method is supposed to do.
$node = $keyObj->makeNode(
key => $key,
nodeProfile => { isLeaf => 0, },
nodeProfile => { leafState => 0, },
);

Foswiki::Exception::Fatal->throw(
Expand Down Expand Up @@ -461,7 +468,7 @@ sub tieNode {
$node->value( \%newHash );

# Tieing of a node makes it non-leaf implcitly.
$node->isLeaf(0);
$node->leafState(0);

return $node;
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Config/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ sub prepareLeafState {
my $this = shift;

foreach my $opt ( keys %{ $this->options } ) {
return 1 if $this->_leafOnlyOpts->{$opt};
return LEAF if $this->_leafOnlyOpts->{$opt};
}

return NOSTATE;
return undef;
}

=begin TML
Expand Down

0 comments on commit f3e2b71

Please sign in to comment.