Skip to content

Commit 2a7a93f

Browse files
committed
Merge pull request #518 from logicminds/case_insensitive
accept any case of boolean strings
2 parents 00b11c2 + f2f2db4 commit 2a7a93f

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ Returns a new string where runs of the same character that occur in this set are
623623

624624
#### `str2bool`
625625

626-
Converts a string to a boolean. This attempts to convert strings that contain values such as '1', 't', 'y', and 'yes' to 'true' and strings that contain values such as '0', 'f', 'n', and 'no' to 'false'. *Type*: rvalue.
626+
Converts a string to a boolean regardless of case. This attempts to convert strings that contain values such as '1', 't', 'y', 'Y', 'YES','yes', and 'TRUE' to 'true' and strings that contain values such as '0', 'f','F', 'N','n', 'NO','FALSE', and 'no' to 'false'. *Type*: rvalue.
627627

628628
#### `str2saltedsha512`
629629

lib/puppet/parser/functions/str2bool.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
module Puppet::Parser::Functions
66
newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
77
This converts a string to a boolean. This attempt to convert strings that
8-
contain things like: y, 1, t, true to 'true' and strings that contain things
9-
like: 0, f, n, false, no to 'false'.
8+
contain things like: Y,y, 1, T,t, TRUE,true to 'true' and strings that contain things
9+
like: 0, F,f, N,n, false, FALSE, no to 'false'.
1010
EOS
1111
) do |arguments|
1212

@@ -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)