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

puppet generate types incorrectly quotes backslashes in regular expressions when rendering Patterns

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Duplicate
    • PUP 4.10.5, PUP 5.1.0
    • None
    • None
    • None
    • Customer Feedback
    • Needs Assessment

    Description

      This is a minimal test case reproducing a customer report from slack.

      Let's start out with this reduction of https://github.com/puppetlabs/puppetlabs-mysql/blob/d066549a0d79cda2b74e81254d3618538f4ba7eb/lib/puppet/type/mysql_datadir.rb :

      david@davids:~/git/tmp/test/testmod$ cat lib/puppet/type/mysql_datadir.rb 
      Puppet::Type.newtype(:mysql_datadir) do
        newparam(:works) do
          newvalues(%r{^/})
        end
       
        newparam(:fails) do
          newvalues(%r{^\/$})
        end
      end
      david@davids:~/git/tmp/test/testmod$ pry
      [1] pry(main)> %r{^\/$}
      => /^\/$/
      [2] pry(main)> 
      

      As you can see, the fails property has a valid regular expression in newvalues.

      Let's see what puppet generate types does:

      david@davids:~/git/tmp/test/testmod$ bundle exec puppet generate types --modulepath ..Notice: Generating Puppet resource types.
      Notice: No files were generated because all inputs were up-to-date.
      david@davids:~/git/tmp/test/testmod$ cat /home/david/.puppetlabs/etc/code/environments/production/.resource_types/mysql_datadir.pp# This file was automatically generated on 2017-09-08 13:58:29 +0100.
      # Use the 'puppet generate types' command to regenerate this file.
       
      Puppet::Resource::ResourceType3.new(
        'mysql_datadir',
        [
       
        ],
        [
          # Values can match `/^\//`.
          Puppet::Resource::Param(Pattern[/^\//], 'works'),
       
          # Values can match `/^\/$/`.
          Puppet::Resource::Param(Pattern[/^\\/$/], 'fails')
        ],
        {
        },
        true,
        false)
      david@davids:~/git/tmp/test/testmod$ bundle exec puppet parser validate /home/david/.puppetlabs/etc/code/environments/production/.resource_types/mysql_datadir.pp
      Error: Could not parse for environment production: Syntax error at '' at /home/david/.puppetlabs/etc/code/environments/production/.resource_types/mysql_datadir.pp:14:42
      david@davids:~/git/tmp/test/testmod$ 
      

      The fails regular expression gets rendered with a double backslash, causing the rendered PCore code to be invalid puppet syntax.

      The customer reporting this on slack was running puppet 4.10.5, while I could reproduce this locally using puppet 5.1.0.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              david.schmitt David Schmitt
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support