From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id AD5761F463 for ; Sun, 29 Dec 2019 12:50:28 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D2129120B84; Sun, 29 Dec 2019 21:50:11 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 63153120B7E for ; Sun, 29 Dec 2019 21:50:09 +0900 (JST) Received: by filterdrecv-p3mdw1-56c97568b5-cmkgv with SMTP id filterdrecv-p3mdw1-56c97568b5-cmkgv-18-5E08A102-4C 2019-12-29 12:50:10.86908554 +0000 UTC m=+1080424.463832134 Received: from herokuapp.com (unknown [54.145.162.235]) by ismtpd0053p1iad2.sendgrid.net (SG) with ESMTP id qltholZQSxW7xT5hTXC3lg for ; Sun, 29 Dec 2019 12:50:10.790 +0000 (UTC) Date: Sun, 29 Dec 2019 12:50:10 +0000 (UTC) From: hsbt@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72230 X-Redmine-Project: ruby-master X-Redmine-Issue-Id: 11531 X-Redmine-Issue-Author: panasyuk X-Redmine-Issue-Assignee: knu X-Redmine-Sender: hsbt 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: =?us-ascii?Q?9+ToIm+BmphpEzrVEr2fqVDpB0VofQNbgfqsVvtPdY288Y6dvoTVdM2zqXz8Nc?= =?us-ascii?Q?knmLz5yraJHuD=2FCtr1a8tAOe2umuEmJAnPORv+x?= =?us-ascii?Q?4R12kAfH36c6sqkFNaEiGMUPb02qbqnjTEO5uEA?= =?us-ascii?Q?EvCmKgU6KNvQ7kZ9KpgJNCNT6i39YWl=2FgNeU1RK?= =?us-ascii?Q?y4p=2FyldA2cUqUdiyn7ib29dJ0+kovFM0oNElGn=2F?= =?us-ascii?Q?FK13Ll1aQuOJCGHHI=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96570 Subject: [ruby-core:96570] [Ruby master 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 hsbt (Hiroshi SHIBATA). Assignee set to knu (Akinori MUSHA) Status changed from Open to Assigned ---------------------------------------- Bug #11531: IPAddr#== implements wrong logic https://bugs.ruby-lang.org/issues/11531#change-83528 * Author: panasyuk (Aleksander Panasyuk) * Status: Assigned * Priority: Normal * Assignee: knu (Akinori MUSHA) * Target version: * 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/