Bug #1759

Numeric comparison does not work as expected in if statements

Added by Todd Zullinger almost 2 years ago. Updated almost 2 years ago.

Status:Closed Start:11/19/2008
Priority:Normal Due date:
Assignee:Brice Figureau % Done:

0%

Category:language
Target version:0.24.7
Affected version:0.24.6 Branch:
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 almost 2 years ago

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

Updated by Brice Figureau almost 2 years ago

  • Status changed from Accepted to Ready for Testing
  • 3 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 almost 2 years ago

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

Updated by Brice Figureau almost 2 years ago

  • Status changed from Ready for Testing to Ready for Checkin

I think it can be merged…

Updated by James Turnbull almost 2 years ago

  • Status changed from Ready for Checkin to Closed

Pushed in commit:“1ad33cc1499bc9c5fee89d921c219b06986c34b5” in branch 0.24.x

Also available in: Atom PDF