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

String to integer conversion fails

    Details

    • Template:
      PUP Bug Template
    • Team:
      Coremunity
    • Method Found:
      Needs Assessment
    • CS Priority:
      Reviewed
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      Conversion to Integer would give an error when asking for conversion of a decimal string with leading zeros. For example, conversion of "08" with explicit radix 10 would flag this as an error as if the string was supposed to be a valid octal number. This is now fixed so that `Integer("08", 10)` works as expected.
      Show
      Conversion to Integer would give an error when asking for conversion of a decimal string with leading zeros. For example, conversion of "08" with explicit radix 10 would flag this as an error as if the string was supposed to be a valid octal number. This is now fixed so that `Integer("08", 10)` works as expected.
    • QA Risk Assessment:
      Needs Assessment

      Description

      Puppet Version:2018.1.5
      Puppet Server Version:5.5.8
      OS Name/Version: RHEl and Solaris

      Desired Behavior: 

      Convert "08" from a string to an integer successfully on puppet run.

      Actual Behavior:

      Fails to convert "08" from a string to an integer on a puppet run.

      Some of our newly added code was failing on what seems to be a valid String -> Integer conversion.

      A minimal case to reproduce:

      This, which is essentially the same as one of the examples in the docs (https://puppet.com/docs/puppet/5.5/function.html#conversion-to-integer) works:

      1. puppet apply -e 'notify { "message": message => Integer("010", 10) }' 
        Notice: Compiled catalog for denga02l.unix.anz in environment production in 0.05 seconds 
        Notice: 10 
        Notice: /Stage[main]/Main/Notify[message]/message: defined 'message' as 10 
        Notice: Applied catalog in 0.26 seconds

      As you can see the "radix" argument to specify base 10 makes it it correctly interpret the string as a decimal number

      1. puppet apply -e 'notify { "message": message => Integer("07", 10) }'
        Notice: Compiled catalog for pe-201817-master.puppetdebug.vlan in environment production in 0.11 seconds
        Notice: 7
        Notice: /Stage[main]/Main/Notify[message]/message: defined 'message' as 7
        Notice: Applied catalog in 0.30 seconds

      But this fails:

      1. puppet apply -e 'notify { "message": message => Integer("08", 10) }' 
        Error: Evaluation Error: Error while evaluating a Function Call, 'new' The string '08' cannot be converted to Integer (line: 1, column: 33) on node denga02l.unix.anz

      Since the first example correctly interprets the string I suspect that there are two passes over it - one of which is trying to interpret the value as octal, and the second which is doing the actual conversion.

      This happens on both RHEL and Solaris systems

       

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                henrik.lindberg Henrik Lindberg
                Reporter:
                jason.stewart Jason Stewart
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: