TLINDEN / Data-Validate-Struct

Data::Validate::Struct - Validate recursive Hash Structures
http://search.cpan.org/dist/Data-Validate-Struct/
1 stars 3 forks source link

Do not create hash entries during validate. #6

Closed bluhm closed 1 year ago

bluhm commented 1 year ago

The new hash ref check in Data::Validate::Struct version 0.11 unconditionally accesses the fields in the hash to be validated. If the key does not exists, the config tree given to validate() changes when reading the reference type of the non nonexistent value. Only do the type check if the subtree exists. This restores old behavior of 0.10 and tests of my OSPF::LSDB module pass again.

TLINDEN commented 1 year ago

HI,

could you please open an issue and provide a test case? While I understand that accessing the ref w/o checking that it exists is bad, I don't see how it modifies the hash under test:

perl -de0
  DB<1> $hash = {blah => 1} 

  DB<2> use Data::Dumper 

  DB<3> p Dumper($hash) 
$VAR1 = { 
          'blah' => 1 
        }; 

  DB<4> $hash_ref = ref $hash->{"kuk"};

  DB<5> p Dumper($hash)
$VAR1 = {
          'blah' => 1 
        }; 

Thanks a lot in advance!

bluhm commented 1 year ago

My fix is wrong. Thanks @stigmh for your analysis.