IPAddr#mask method accepts arguments other than integers.

Open
#94 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
networking

Research direction

Start at the IPAddr#mask method and reproduce the float and array examples from the issue. The change is done when non-integer arguments raise IPAddr::InvalidPrefixError while integer masks continue to work as expected.

Written by the indexing model from the issue text.

Description

IPAddr#mask method expects an integer argument, but it accepts non-integer values (such as floats or arrays) if passed.

ip = IPAddr.new('1.2.3.4')

p ip.mask(0.1)
# => #<IPAddr: IPv4:0.0.0.0/128.0.0.0>
p ip.mask(1.2)
# => #<IPAddr: IPv4:0.0.0.0/192.0.0.0>
p ip.mask(11.3)
# => #<IPAddr: IPv4:1.0.0.0/255.240.0.0>
p ip.mask([])
# => `mask!': undefined method `<' for []:Array (NoMethodError)

So, I think it is better to restrict the arguments of this method to integers and throw an exception if they are not integers.
Like this.

ip = IPAddr.new('1.2.3.4')

p ip.mask(0.1)
# => `mask!': invalid mask 0.1 (IPAddr::InvalidPrefixError)

I'm currently implementing this improvement and want to submit a pull request as a contribute to this repo.
Would this be acceptable?

Dominant language
Ruby
Stars
82
Forks
42
Avg merge
2h 24m
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/ipaddr

All issues in ruby/ipaddr

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.