Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Random::Formatter #34

Merged
merged 5 commits into from
Dec 2, 2024
Merged

Removed Random::Formatter #34

merged 5 commits into from
Dec 2, 2024

Conversation

hsbt
Copy link
Member

@hsbt hsbt commented Dec 2, 2024

This is another try with #29

@hsbt hsbt force-pushed the removed-random-formatter branch from ab4083a to 2fdde4f Compare December 2, 2024 03:57
@hsbt hsbt force-pushed the removed-random-formatter branch from 2fdde4f to 40ddef8 Compare December 2, 2024 03:58
@hsbt hsbt merged commit af69c46 into master Dec 2, 2024
26 checks passed
@hsbt hsbt deleted the removed-random-formatter branch December 2, 2024 04:45
@jdelStrother
Copy link

jdelStrother commented Dec 2, 2024

FWIW I think this causes problems with Rails on ruby 3.2.

Rails was using SecureRandom.alphanumeric here - https://github.com/rails/rails/blob/4060253ea7bf1a04c7b2368ffc17ddcf991997f9/activesupport/lib/active_support/core_ext/securerandom.rb#L20, but now throws wrong number of arguments (given 2, expected 0..1).

With the removal of SecureRandom.alphanumeric, that falls back to Random.alphanumeric. On ruby 3.2, that only accepts a single argument:

  def alphanumeric(n=nil)
    n = 16 if n.nil?
    choose(ALPHANUMERIC, n)
  end

@nevans
Copy link
Contributor

nevans commented Dec 2, 2024

As far as I can tell, the only functional changes to Random::Formatter between v0.2.0 (which was installed with ruby 3.1.6) and v0.3.2 are:

  • #alphanumeric keyword arg for characters (which affects Rails, as @jdelStrother mentioned)
  • #uuid_v7 (and #uuid_v4 alias)
$ rbenv shell 3.2.6
$ gem install securerandom -v0.3.2
Fetching securerandom-0.3.2.gem
Successfully installed securerandom-0.3.2
Parsing documentation for securerandom-0.3.2
Installing ri documentation for securerandom-0.3.2
Done installing documentation for securerandom after 0 seconds
1 gem installed
$ ruby -rsecurerandom -e "puts SecureRandom.uuid_v7"
0193889a-f355-76b5-bff8-9e46efa743d0
$ gem install securerandom -v0.4.0
Fetching securerandom-0.4.0.gem
Successfully installed securerandom-0.4.0
Parsing documentation for securerandom-0.4.0
Installing ri documentation for securerandom-0.4.0
Done installing documentation for securerandom after 0 seconds
1 gem installed
$ ruby -rsecurerandom -e "puts SecureRandom.uuid_v7"
-e:1:in `<main>': undefined method `uuid_v7' for SecureRandom:Module (NoMethodError)

puts SecureRandom.uuid_v7
                 ^^^^^^^^
Did you mean?  uuid

rafaelfranca added a commit to rails/rails that referenced this pull request Dec 2, 2024
In ruby/securerandom#34, Random::Formatter was
removed from securerandom. This change broke the alphanumeric method
signature in Ruby 3.2 since the `chars` parameter isn't available
there yet.
@hsbt
Copy link
Member Author

hsbt commented Dec 3, 2024

@jdelStrother @nevans Thank you for sharing that. I and @nobu couldn't care these cases before removing Random::Formatter. I'll consider them with compatibility.

byroot pushed a commit to rails/rails that referenced this pull request Dec 3, 2024
In ruby/securerandom#34, Random::Formatter was
removed from securerandom. This change broke the alphanumeric method
signature in Ruby 3.2 since the `chars` parameter isn't available
there yet.
byroot pushed a commit to rails/rails that referenced this pull request Dec 3, 2024
In ruby/securerandom#34, Random::Formatter was
removed from securerandom. This change broke the alphanumeric method
signature in Ruby 3.2 since the `chars` parameter isn't available
there yet.
@nevans
Copy link
Contributor

nevans commented Dec 3, 2024

@hsbt Would it be possible (this close to the 3.4 release) to create a new random-formatter gem? For full backward compatibility, it should be an explicit dependency of securerandom. I created a proof-of-concept here: https://github.com/nevans/securerandom/tree/random-formatter. It shouldn't be merged into this repo, so I won't create a PR. But here's the diff, for comparison: master...nevans:securerandom:random-formatter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants