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

Case and Selector match should be deep

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Done
    • PUP 3.7.5
    • PUP 3.8.0, PUP 4.1.0
    • None
    • None
    • 1
    • Language 2015-04-01, Language 2015-04-15
    • New Feature

    Description

      Case and selector match should be recursive. Currently, the match operator only performs a surface level match.

      case [green, 2, $whatever] {
        [/ee/, Integer[0,10], default] : { notice 'yes' }
        default: { notice 'no' }
      }
      

      The above example should notice 'yes', it currently notices 'no'.

      UPDATE

      Recursive matching means that the same matching rules (as for the surface level) now applies recursively:

      • A literal default accepts any value (e.g. [1,2,3] is matched by [1, default, 3] )
      • A regexp can match a String value (e.g. "hello world" is matched by /hello .*/)
      • A data type can match a value of that type (e.g. 3 matches Integer[1,10])
      • Arrays must match in size to match the option
      • Hashes match if the keys in the option have an equal key in the tested value, and the option key's value match the tested value.
      • Array entries and hash entries (values) are processed recursively.

      The relevant section in the specification is: https://github.com/puppetlabs/puppet-specifications/blob/4.0.0/language/expressions.md#case-expression
      (note the reference to the tag 4.0.0 as there are additional features in the 4.1.0 version - notably PUP-4193 - lambda support).

      risk assessment: medium (manual validate for now)
      probability: low
      severity: medium (work arounds)
      test layer: unit

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              henrik.lindberg Henrik Lindberg
              Eric Thompson Eric Thompson
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support