Skip to content

Commit 93c4151

Browse files
committed
(MODULES-905) Narrow the confinement in bool2str
Previously, bool2str() accepted a broad array of boolean values and bare strings, without any attempt to validate that the strings in any way resembled "true" or "false" (or any of the other values bool2num() accepts). This commit narrows the input confinement to TrueClass and FalseClass, which means that bool2str() will only interpolate strict boolean values now.
1 parent 0761fcf commit 93c4151

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/puppet/parser/functions/bool2str.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module Puppet::Parser::Functions
66
newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
77
Converts a boolean to a string.
8-
Requires a single boolean or string as an input.
8+
Requires a single boolean as an input.
99
EOS
1010
) do |arguments|
1111

@@ -15,15 +15,12 @@ module Puppet::Parser::Functions
1515
value = arguments[0]
1616
klass = value.class
1717

18-
# We can have either true or false, or string which resembles boolean ...
19-
unless [FalseClass, TrueClass, String].include?(klass)
20-
raise(Puppet::ParseError, 'bool2str(): Requires either ' +
21-
'boolean or string to work with')
18+
# We can have either true or false, and nothing else
19+
unless [FalseClass, TrueClass].include?(klass)
20+
raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with')
2221
end
2322

24-
result = value.is_a?(String) ? value : value.to_s
25-
26-
return result
23+
return value.to_s
2724
end
2825
end
2926

0 commit comments

Comments
 (0)