Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5350

Puppet filter function does not behave consistently across all supported argument types.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.2.2
    • Fix Version/s: PUP 3.8.4, PUP 4.2.3
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2015-10-14, Language 2015-10-28
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      The filter() function did not behave according to specification when filtering a hash as it did not enforce that only boolean true as a return from the code block would include the element in the result. Instead, any "truthy" value was accepted. Now, only boolean true will include an element in the result.
      Show
      The filter() function did not behave according to specification when filtering a hash as it did not enforce that only boolean true as a return from the code block would include the element in the result. Instead, any "truthy" value was accepted. Now, only boolean true will include an element in the result.

      Description

      The overload of the filter function that takes a Hash behaves differently from the other overloads that take an "enumerable" type.

      For example:

      notice({a => 1, b => 2, c => 3}.filter |$k, $v| { $v })
      

      Will output

      {a => 1, b=> 2, c => 3}
      

      However:

      notice([1, 2, 3].filter |$v| { $v })
      

      Will output:

      []
      

      The first example returns an Integer and results in not filtering the element. The second example also returns an Integer, but this results in filtering the element.

      One of these behaviors is incorrect and should be made consistent.

      Cause of bug:

      In the filter function's implementation, the Hash overload uses hash#select and returns the result of yielding to the lambda, which Ruby treats as true if the value is truthy. The enumerable overload instead has a direct comparison of the lambda's return value to true.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  peter.huene Peter Huene
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Zendesk Support