From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id DDE8B1B00050 for ; Mon, 7 Nov 2016 00:52:31 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id CE4E4B5D86F for ; Mon, 7 Nov 2016 01:23:12 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id A74F818CC818 for ; Mon, 7 Nov 2016 01:23:12 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E18441205F6; Mon, 7 Nov 2016 01:23:11 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 52E171205ED for ; Mon, 7 Nov 2016 01:23:06 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=nxvYv94qCc5FmCUjwny0FUoU1Bs=; b=nqQLuF4mXu/igqAjyh lHjRW4W5qGGkaTWQucJIK1p57EKcThuscnOwIE5YeuGNbwtznHovL1AJODcAd9l1 s6Upbf61YS3oICamD9B2yY5mQ8Uid69GAkkzrb3ETKWEOuXtzzRpnAsw541qw5PV 6WiHshkwkYz8Quc+7x2c8jVYY= Received: by filter0501p1mdw1.sendgrid.net with SMTP id filter0501p1mdw1-32763-581F58C0-18 2016-11-06 16:22:24.254027334 +0000 UTC Received: from herokuapp.com (ec2-54-81-190-183.compute-1.amazonaws.com [54.81.190.183]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id rLstcaKxTmGUeIsJr0RcPg Sun, 06 Nov 2016 16:22:24.025 +0000 (UTC) Date: Sun, 06 Nov 2016 16:22:24 +0000 From: knu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 52885 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11531 X-Redmine-Issue-Author: panasyuk X-Redmine-Sender: knu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5TgUN3lGXlOaUjX34aymeH6OOVfC7Wql8b/q v50CD5oSLCHzUd8kFl7jtKQOYPBWb9JgwXmuejMCpVlIlYBN9OIJZ80XA4jrBjxrxEPU/bidYsAbnt eiqBuaASuQu652E3KdTeEFrK1H1253EnkMad2HgUXi2rAj0G1Cf9ep0EGA== X-ML-Name: ruby-core X-Mail-Count: 78018 Subject: [ruby-core:78018] [Ruby trunk Bug#11531] IPAddr#== implements wrong logic X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11531 has been updated by Akinori MUSHA. I think this is intentional. IPAddr represents an IP address, not an IP network, so it does not consider a difference in netmasks as significant. ---------------------------------------- Bug #11531: IPAddr#== implements wrong logic https://bugs.ruby-lang.org/issues/11531#change-61361 * Author: Aleksander Panasyuk * Status: Open * Priority: Normal * Assignee: * ruby -v: 2.1.5p273 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- # Description IPAddr#== should implement the logic of comparison of two IPAddr instances. This generally means that it compares two IP addresses. Lets look at the code of this method: https://github.com/ruby/ruby/blob/c8b3f1b470e343e7408ab5883f046b1056d94ccc/lib/ipaddr.rb#L151 `return @family == other.family && @addr == other.to_i` It returns the result of comparison of the families and the addresses, but it should also compare the netmask which describes the network where this address is located. The code below shows the test case for this comparison: ` ip1 = IPAddr.new '195.51.100.0/24' ip2 = IPAddr.new '195.51.100.0/26' ip1 == ip2 #=> true ` This code shows that two identical IP addresses from different networks are equal. But the result should be `false` because these addresses are not identical. # Possible solution Depending on Feature #11210 i would propose following implementation of this method: ` def ==(other) other = coerce_other(other) return @family == other.family && @addr == other.to_i && @mask_addr == other.netmask end ` -- https://bugs.ruby-lang.org/