Skip to content

Commit 882af28

Browse files
committed
accept any case of boolean strings
* previously the str2bool function did not accept 'TRUE' as a bool this causes the function to know accept TRUE | FALSE strings as a boolean type in order to be converted to a proper boolean. * This would also cause Y|N, YES, NO to be accepted as boolean types as well.
1 parent 6a1afae commit 882af28

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/puppet/parser/functions/str2bool.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ module Puppet::Parser::Functions
3232
# We yield false in this case.
3333
#
3434
when /^$/, '' then false # Empty string will be false ...
35-
when /^(1|t|y|true|yes)$/ then true
36-
when /^(0|f|n|false|no)$/ then false
35+
when /^(1|t|y|true|yes)$/i then true
36+
when /^(0|f|n|false|no)$/i then false
3737
when /^(undef|undefined)$/ then false # This is not likely to happen ...
3838
else
3939
raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given')

spec/functions/str2bool_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /Unknown type of boolean given/) }
1111

1212
describe 'when testing values that mean "true"' do
13-
[ '1', 't', 'y', 'true', 'yes', true ].each do |value|
13+
[ 'TRUE','1', 't', 'y', 'true', 'yes', true ].each do |value|
1414
it { is_expected.to run.with_params(value).and_return(true) }
1515
end
1616
end
1717

1818
describe 'when testing values that mean "false"' do
19-
[ '', '0', 'f', 'n', 'false', 'no', false, 'undef', 'undefined' ].each do |value|
19+
[ 'FALSE','', '0', 'f', 'n', 'false', 'no', false, 'undef', 'undefined' ].each do |value|
2020
it { is_expected.to run.with_params(value).and_return(false) }
2121
end
2222
end

0 commit comments

Comments
 (0)