#15305·chef

value_for_platform returns nil instead of false

Author: schrdCreated Sep 26, 2025Updated Jun 3, 2026
LabelsStatus: Untriaged

Description

value_for_platform returns nil if the value in a match is specified as false. It should return false instead of nil.

Chef Version

18.8.11

Platform Version

Debian 13, but that does not change anything.

Replication Case

Start a chef-shell and enter the following statements:

ruby
value_for_platform(node['platform'] => { "~> #{node['platform_version']}.0" => false})
 => nil
value_for_platform(node['platform'] => { "~> #{node['platform_version']}.0" => true})
 => true
value_for_platform(node['platform'] => { "~> #{node['platform_version']}.0" => 1})
 => 1

The problem is in https://github.com/chef/chef/blob/7cd341428c79209ffce3e85f77d5f0705da7dfae/lib/chef/dsl/platform_introspection.rb#L61

If match_versions(node) returns false it won't jump into the elsif in line 61

This should fix it:

ruby
def value_for_node(node)
  platform, version = node[:platform].to_s, node[:platform_version].to_s
  # Check if we match a version constraint via Chef::VersionConstraint::Platform and Chef::Version::Platform
  matched_value = match_versions(node)
  if @values.key?(platform) && @values[platform].key?(version)
    @values[platform][version]
  elsif !matched_value.nil?
    matched_value
  elsif @values.key?(platform) && @values[platform].key?("default")
    @values[platform]["default"]
  elsif @values.key?("default")
   @values["default"]
  else
    nil
  end
end