Skip to content

Commit 24a0f21

Browse files
Merge pull request #1367 from alexjfisher/fix_fqdn_rand_string_regression
Fix `fqdn_rand_string` regression
2 parents 1dee9ef + d6847c0 commit 24a0f21

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Diff for: lib/puppet/functions/stdlib/fqdn_rand_string.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
# @example Example Usage:
1616
# stdlib::fqdn_rand_string(10)
1717
# stdlib::fqdn_rand_string(10, 'ABCDEF!@$%^')
18-
# stdlib::fqdn_rand_string(10, '', 'custom seed')
18+
# stdlib::fqdn_rand_string(10, undef, 'custom seed')
1919
dispatch :fqdn_rand_string do
2020
param 'Integer[1]', :length
21-
optional_param 'String', :charset
21+
optional_param 'Optional[String]', :charset
2222
optional_repeated_param 'Any', :seed
2323
end
2424

25-
def fqdn_rand_string(length, charset = '', *seed)
26-
charset = charset.chars.to_a
27-
28-
charset = (0..9).map(&:to_s) + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty?
25+
def fqdn_rand_string(length, charset = nil, *seed)
26+
charset = if charset && !charset.empty?
27+
charset.chars.to_a
28+
else
29+
(0..9).map(&:to_s) + ('A'..'Z').to_a + ('a'..'z').to_a
30+
end
2931

3032
rand_string = ''
3133
length.times do |current|

Diff for: spec/functions/fqdn_rand_string_spec.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
it { is_expected.to run.with_params('string').and_raise_error(ArgumentError, %r{parameter 'length' expects an Integer\ value, got String}) }
1515
it { is_expected.to run.with_params([]).and_raise_error(ArgumentError, %r{parameter 'length' expects an Integer value, got Array}) }
1616
it { is_expected.to run.with_params({}).and_raise_error(ArgumentError, %r{parameter 'length' expects an Integer value, got Hash}) }
17-
it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{parameter 'charset' expects a String value, got Integer}) }
18-
it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{parameter 'charset' expects a String value, got Array}) }
19-
it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{parameter 'charset' expects a String value, got Hash}) }
17+
it { is_expected.to run.with_params(1, 1).and_raise_error(ArgumentError, %r{parameter 'charset' expects a value of type Undef or String, got Integer}) }
18+
it { is_expected.to run.with_params(1, []).and_raise_error(ArgumentError, %r{parameter 'charset' expects a value of type Undef or String, got Array}) }
19+
it { is_expected.to run.with_params(1, {}).and_raise_error(ArgumentError, %r{parameter 'charset' expects a value of type Undef or String, got Hash}) }
2020
it { is_expected.to run.with_params('100').and_raise_error(ArgumentError, %r{parameter 'length' expects an Integer value, got String}) }
21-
it { is_expected.to run.with_params(100, nil).and_raise_error(ArgumentError, %r{parameter 'charset' expects a String value, got Undef}) }
22-
it { is_expected.to run.with_params(100).and_return(default_charset) }
21+
it { is_expected.to run.with_params(100, nil).and_return(default_charset) }
2322
it { is_expected.to run.with_params(100, '').and_return(default_charset) }
23+
it { is_expected.to run.with_params(100, nil, 'MY_CUSTOM_SEED').and_return(default_charset) }
24+
it { is_expected.to run.with_params(100, '', 'MY_CUSTOM_SEED').and_return(default_charset) }
25+
it { is_expected.to run.with_params(100).and_return(default_charset) }
2426
it { is_expected.to run.with_params(100, 'a').and_return(%r{\Aa{100}\z}) }
2527
it { is_expected.to run.with_params(100, 'ab').and_return(%r{\A[ab]{100}\z}) }
2628
it { is_expected.to run.with_params(100, 'ãβ').and_return(%r{\A[ãβ]{100}\z}) }

0 commit comments

Comments
 (0)