Skip to content

Commit 53b946f

Browse files
committed
Use versioncmp to check Puppet version for 4.10.x compatibility
`Puppet.version.to_f` on Puppet 4.10.0 will evaluate to `4.1`, causing test and behavioural changes when conditionals check that the version is equal or greater than versions such as `4.3`. Version comparisons that are vulnerable to this have been changed to use Puppet's versioncmp implementation, while most others only check for for major version boundaries which is safe.
1 parent b6c04c6 commit 53b946f

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/puppet-syntax/manifests.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def check(filelist)
5959
private
6060
def validate_manifest(file)
6161
Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet::PUPPETVERSION.to_i < 4
62-
Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::PUPPETVERSION.to_f >= 4.3 && Puppet::PUPPETVERSION.to_i < 5)
62+
Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5)
6363
Puppet::Face[:parser, :current].validate(file)
6464
end
6565
end

lib/puppet-syntax/tasks/puppet-syntax.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def initialize(*args)
5454
'true'. The `future_parser setting will be ignored.
5555
EOS
5656
end
57-
if Puppet::PUPPETVERSION.to_f < 4.3 and PuppetSyntax.app_management
57+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') < 0 and PuppetSyntax.app_management
5858
$stderr.puts <<-EOS
5959
[WARNING] Puppet `app_management` has been detected but the Puppet
6060
version is less then 4.3. The `app_management` setting will be ignored.

spec/puppet-syntax/manifests_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
before(:each) {
156156
PuppetSyntax.app_management = true
157157
}
158-
if Puppet::PUPPETVERSION.to_f >= 4.3
158+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
159159
it 'should successfully parse an application manifest on Puppet >= 4.3.0' do
160160
expect(PuppetSyntax.app_management).to eq(true)
161161

0 commit comments

Comments
 (0)