From f2f2db4795fc0e3b9387e1e6c003e8e75efde903 Mon Sep 17 00:00:00 2001 From: Corey Osman Date: Thu, 3 Sep 2015 10:31:51 -0700 Subject: accept any case of boolean strings * previously the str2bool function did not accept 'TRUE' as a bool type. This causes the function to now 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. --- lib/puppet/parser/functions/str2bool.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/puppet/parser/functions/str2bool.rb') diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index 446732e..8def131 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -5,8 +5,8 @@ module Puppet::Parser::Functions newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS This converts a string to a boolean. This attempt to convert strings that -contain things like: y, 1, t, true to 'true' and strings that contain things -like: 0, f, n, false, no to 'false'. +contain things like: Y,y, 1, T,t, TRUE,true to 'true' and strings that contain things +like: 0, F,f, N,n, false, FALSE, no to 'false'. EOS ) do |arguments| @@ -32,8 +32,8 @@ like: 0, f, n, false, no to 'false'. # We yield false in this case. # when /^$/, '' then false # Empty string will be false ... - when /^(1|t|y|true|yes)$/ then true - when /^(0|f|n|false|no)$/ then false + when /^(1|t|y|true|yes)$/i then true + when /^(0|f|n|false|no)$/i then false when /^(undef|undefined)$/ then false # This is not likely to happen ... else raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given') -- cgit v1.2.3 From fded0af0c687bf4f219564dc4dfcd890f4563523 Mon Sep 17 00:00:00 2001 From: Loic Antoine-Gombeaud Date: Wed, 27 Jul 2016 12:59:23 +0200 Subject: Fix str2bool error message --- lib/puppet/parser/functions/str2bool.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/str2bool.rb') diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index 8def131..472506d 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -21,7 +21,7 @@ like: 0, F,f, N,n, false, FALSE, no to 'false'. end unless string.is_a?(String) - raise(Puppet::ParseError, 'str2bool(): Requires either ' + + raise(Puppet::ParseError, 'str2bool(): Requires ' + 'string to work with') end -- cgit v1.2.3