-
Notifications
You must be signed in to change notification settings - Fork 583
bug # 20681 delete() function should not remove elements from original list #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I had changed to using collection = arguments[0].dup instead of rejecting elements from the original list, as done on the previous commit. This change on aproach is needed because the previous solution does not worked on ruby 1.8.7, (silly me, tested only on 1.9.3 and 2.0.0 ). The current fix is more simple and works on ruby 1.8.7, 1.9.3 and 2.0.0. |
item = arguments[1] | ||
|
||
case collection | ||
when Array, Hash | ||
collection.delete item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this whitespace change intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it was a typo error. i will fix that.
I had identified that other delete functions also have this same issue. I will fix that tomorrow. |
@lmello are you planning on filing new pull requests for the other delete functions are you going to append commits to this pull request? If it's the former, I can merge this in. |
On monday i will amend all those commits into a single one. Then you could merge if everything is ok. I will fill new pull requests for the other functions. best. |
…l list The setup: list with 3 elements, delete one: $test_list = [‘a’, ‘b’, ‘c’] $test_deleted = delete($test_list, ‘a’) Print out the elements in ‘test_deleted’: notify { ‘group_output2’: withpath => true, name => “$cfeng::test_deleted”, } Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc Good! Run-on output shows that ‘a’ was deleted Print out the elements in ‘test_list’: notify { ‘group_output1’: withpath => true, name => “$cfeng::test_list”, } Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc WHAT!? 'a' was deleted from ‘test_list’ as well! Expected abc as output! This behaviour is confirmed for string, hash and array. This is fixed on this commit, I had added two spec tests to cover that cases. bug #20681 spec test for delete() function. I had forgot in the last commit the spec test for hash in the delete function. bug # 20681 delete() function change aproach. Instead of rejecting elements from the original list, we use collection = arguments[0].dup . then latter we could continue to use delete and gsub! on collection without impact on original argument. this is a better solution than the previous one, and works on ruby 1.8.7, 1.9.3 and 2.0.0. The previous solution does not work on ruby 1.8.7. delete function remove typo whitespace. fix typo whitespaces.
please merge. :-) |
bug # 20681 delete() function should not remove elements from original list
summary: merged into master in 5cc5e29; thanks for the contribution! |
The setup: list with 3 elements, delete one:
$test_list = [‘a’, ‘b’, ‘c’]
$test_deleted = delete($test_list, ‘a’)
Print out the elements in ‘test_deleted’:
notify { ‘group_output2’: withpath => true, name => “$cfeng::test_deleted”, }
Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc
Good! Run-on output shows that ‘a’ was deleted
Print out the elements in ‘test_list’:
notify { ‘group_output1’: withpath => true, name => “$cfeng::test_list”, }
Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc
WHAT!? 'a' was deleted from ‘test_list’ as well! Expected abc as output!
This behaviour is confirmed for string, hash and array.
This is fixed on this commit, I had added two spec tests to cover that cases.