puppetlabs / facter

Collect and display system facts
https://puppet.com/open-source/#osp
Apache License 2.0
616 stars 494 forks source link

Evaluate confine block in case-insensitive way #2699

Closed mhashizume closed 3 months ago

mhashizume commented 3 months ago

Prior to this commit when a user provided a confine block, Facter would downcase the value when evaluating it.

For example:

confine :kernel do |value|
  value == "Linux"
end

While Facter's public documentation states that this is a valid way to write a confine block, it would incorrectly and unexpectedly evaluate as false on Linux systems.

However, these other styles of confine would return true:

confine :kernel => "Linux"

confine kernel: "Linux"

This downcasing behavior was introduced in 7a81945 as a way of comparing values in a case-insensitive way. However when block confines were introduced in e4c8689, it added block evaluation before value comparison, making the case-insensitive comparison moot with blocks.

This commit retains existing behavior of evaluating a confine block with a downcased fact value, while adding evaluation with the raw fact value to ensure expected behavior.