mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[ruby/securerandom] Restore SecureRandom.alphanumeric same as Random::Formatter.alphanumeric of Ruby 3.3/3.4
Fixes https://github.com/ruby/securerandom/pull/35
fbb36e36cc
This commit is contained in:
parent
5e838197a3
commit
3a4433dddd
2 changed files with 16 additions and 0 deletions
|
@ -51,6 +51,16 @@ module SecureRandom
|
||||||
return gen_random(n)
|
return gen_random(n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2
|
||||||
|
def alphanumeric(n = nil, chars: ALPHANUMERIC)
|
||||||
|
if RUBY_VERSION < '3.3'
|
||||||
|
n = 16 if n.nil?
|
||||||
|
choose(chars, n)
|
||||||
|
else
|
||||||
|
super n, chars: chars
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
|
|
@ -9,6 +9,12 @@ class TestSecureRandom < Test::Unit::TestCase
|
||||||
@it = SecureRandom
|
@it = SecureRandom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_alphanumeric_with_chars
|
||||||
|
assert_nothing_raised(ArgumentError) do
|
||||||
|
@it.alphanumeric(1, chars: ("0".."9").to_a)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This test took 2 minutes on my machine.
|
# This test took 2 minutes on my machine.
|
||||||
# And 65536 times loop could not be enough for forcing PID recycle.
|
# And 65536 times loop could not be enough for forcing PID recycle.
|
||||||
# TODO: We should run this test only on GitHub Actions.
|
# TODO: We should run this test only on GitHub Actions.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue