IPAddr#mask method accepts arguments other than integers.

未关闭
#94 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
networking

调研方向

从 IPAddr#mask 方法开始,复现 issue 中的 float 和 array 示例。当非整数参数引发 IPAddr::InvalidPrefixError,同时整数掩码继续按预期工作时,此更改即完成。

由索引模型根据 Issue 内容生成。

描述

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?

主要语言
Ruby
星标
82
派生
42
平均合并
2 小时 24 分钟
30 天内合并 PR
3

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/ipaddr 的其他 Issue

查看 ruby/ipaddr 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。