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

IPAddr#freeze is broken #35

Closed
Tietew opened this issue Dec 9, 2021 · 6 comments
Closed

IPAddr#freeze is broken #35

Tietew opened this issue Dec 9, 2021 · 6 comments

Comments

@Tietew
Copy link

Tietew commented Dec 9, 2021

After freezing IPAddr instance, a lot of methods die with FrozenError: can't modify frozen IPAddr.

$ RBENV_VERSION=3.1.0-dev irb
ruby 3.1.0dev (2021-12-08T23:58:25Z master 45c5794d32) [x86_64-linux]
irb(main):001:0> require 'ipaddr'
=> true
irb(main):002:0> IPAddr.new('127.0.0.1').freeze.to_range
/usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:509:in `set': can't modify frozen IPAddr: #<IPAddr: IPv4:127.0.0.1/255.255.255.255> (FrozenError)
        from /usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:413:in `to_range'
irb(main):003:0> IPAddr.new('127.0.0.1').freeze.include?('127.0.0.1')
/usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:509:in `set': can't modify frozen IPAddr: #<IPAddr: IPv4:127.0.0.1/255.255.255.255> (FrozenError)
        from /usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:413:in `to_range'
        from /usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:178:in `include?'
irb(main):004:0> IPAddr.new('127.0.0.1').freeze.succ
/usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:509:in `set': can't modify frozen IPAddr: #<IPAddr: IPv4:127.0.0.1/255.255.255.255> (FrozenError)
        from /usr/local/anyenv/envs/rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/ipaddr.rb:377:in `succ'

It seems that clone.set() in these methods should be clone(freeze: false).set() or dup.set()

@esparta
Copy link
Contributor

esparta commented Dec 13, 2021

IMO this is a valid use case meaning the bug should be fixed.

I went ahead and got a proposal to patch it here: #36

@ioquatix
Copy link
Member

Thanks for this, feel free to close this issue if this was the only case where it was broken. Thanks!

@respire
Copy link

respire commented Jan 1, 2022

Hello, I met this issue in ruby-3.1 release.
Maybe #36 is not in 3.1 stdlib ipaddr 1.2.3?

Snipaste_2022-01-01_09-55-49

gem info ipaddr

*** LOCAL GEMS ***

ipaddr (1.2.3)
    Authors: Akinori MUSHA, Hajimu UMEMOTO
    Homepage: https://github.com/ruby/ipaddr
    Licenses: Ruby, BSD-2-Clause
    Installed at (default): /home/ubuntu/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0

    A class to manipulate an IP address in ruby```

I can temporarily solve it by putting this line at my gemfile

gem 'ipaddr', git: 'https://github.com/ruby/ipaddr.git', ref: '77fe1fca0abb56f7f07725c0a3803d53a315c853'

@ioquatix
Copy link
Member

ioquatix commented Jan 2, 2022

I don't know why this isn't synchronised.

@respire
Copy link

respire commented Feb 25, 2022

https://bugs.ruby-lang.org/issues/18570

now in ruby 3.1.1
https://www.ruby-lang.org/en/news/2022/02/18/ruby-3-1-1-released/

I have upgraded my application and verified it works

ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]
bundle info ipaddr
  * ipaddr (1.2.4)
        Summary: A class to manipulate an IP address in ruby
        Homepage: https://github.com/ruby/ipaddr
        Path: $HOME/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/ipaddr-1.2.4
        Default Gem: yes

@hsbt
Copy link
Member

hsbt commented Feb 25, 2022

ipaddr-1.2.4 is contained 3.1.1.

ruby/ruby@7315972

@hsbt hsbt closed this as completed Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants