Bug #1759

avatar

Numeric comparison does not work as expected in if statements

Added by Todd Zullinger 7 months ago. Updated 7 months ago.

Status:Closed Start:11/19/2008
Priority:Normal Due date:
Assigned to:avatarBrice Figureau % Done:

0%

Category:language
Target version:0.24.7
Complexity:

Trivial

Affected version:

0.24.6

Keywords:

Votes: 0

Description

Attempting to use the new if statements in 0.24.6, I found that numeric comparisons did not work as I would expect. An example:

$operatingsystemrelease = 10 # From facter
if $operatingsystemrelease > 9 # This is not true. Huh?

Thinking it might be comparing the facter variable as a string, try it hardcoded:

if 10 > 9 # Still not true. Odd.

if 10 > 09 # This is true.

So, is the comparison being done character by character or is it just doing string comparison? The examples in the documentation indicate that using numeric comparisons are intended to work (with examples like "if $ram > 1024" and "if ( $processor_count > 2 )" at http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#if-else).

fujin posted a handy demo at http://pastie.org/318391

History

Updated by James Turnbull 7 months ago

avatar
  • Status changed from Unreviewed to Accepted
  • Target version set to 0.24.7

Updated by Brice Figureau 7 months ago

avatar
  • Status changed from Accepted to Ready for Testing
  • Complexity changed from Unknown to Trivial

Hi,

It is fixed in tickets/0.24.x/1759 in my github repository:
http://github.com/masterzen/puppet/tree/tickets%2F0.24.x%2F1759

Commit: dd9d4486f4d6c8e033b891c5f5d33750b8ba3d0e

Updated by Todd Zullinger 7 months ago

avatar

Confirmed that this is fixed. Thanks for the quick patch.

Updated by Brice Figureau 7 months ago

avatar
  • Status changed from Ready for Testing to Ready for Checkin

I think it can be merged...

Updated by James Turnbull 7 months ago

avatar
  • Status changed from Ready for Checkin to Closed

Pushed in 1ad33cc1499bc9c5fee89d921c219b06986c34b5 in branch 0.24.x

Also available in: Atom PDF