diff options
author | Leonardo Rodrigues de Mello <l@lmello.eu.org> | 2013-09-16 10:33:58 -0300 |
---|---|---|
committer | Leonardo Rodrigues de Mello <l@lmello.eu.org> | 2013-09-17 12:05:23 -0300 |
commit | 51d96088c1d6bde8dae511d6a93bc6775e716f60 (patch) | |
tree | 77823de2bd75cd72e30ede20379b0c27bb406687 /lib | |
parent | 806430224ad0da860be3761ab83f1e574b64fc60 (diff) | |
download | puppet-stdlib-51d96088c1d6bde8dae511d6a93bc6775e716f60.tar.gz puppet-stdlib-51d96088c1d6bde8dae511d6a93bc6775e716f60.tar.bz2 |
(#20681) fix behaviour of delete_values
The issue #20681 describe the error of delete() function
removing the elements from the origin array/hash/string.
This issue affected other delete functions. Because
ruby delete and delete_if functions make destructive
changes to the origin array/hash.
The delete_undef_values removed elements from the
origin hash and this is not the desired behaviour.
To solve this, we should dup or clone the hash
before using the delete or delete_if ruby functions.
This fix the problem and add unit tests, so we could
enforce this behaviour and prevent regressions.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/functions/delete_values.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index 17b9d37..ca8eef5 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -21,6 +21,6 @@ Would return: {'a'=>'A','c'=>'C','B'=>'D'} raise(TypeError, "delete_values(): First argument must be a Hash. " + \ "Given an argument of class #{hash.class}.") end - hash.delete_if { |key, val| item == val } + hash.dup.delete_if { |key, val| item == val } end end |