From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.8 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RP_MATCHES_RCVD,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 797451F4CF for ; Thu, 31 Dec 2015 19:23:03 +0000 (UTC) From: Eric Wong To: Subject: [PATCH v3] resolv: attempt to fix Resolv::LOC::Coord.create Date: Thu, 31 Dec 2015 19:23:03 +0000 Message-Id: <20151231192303.26488-1-e@80x24.org> List-Id: This seems to have never worked in the first place: * "$1 < 180" where $1 is a string raises ArgumentError * regexps in the assignment for "hemi" reset $1 and clobber $2, $3, $4 * orientation is a frozen string literal which we append to * "$4[[/NS/],1]" has square brackets in the wrong place ref: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/72635 --- lib/resolv.rb | 10 ++++++---- test/resolv/test_resource.rb | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/resolv.rb b/lib/resolv.rb index 9a981b9..3b3f710 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -2699,10 +2699,12 @@ def self.create(arg) return arg when String coordinates = '' - if Regex =~ arg && $1<180 - hemi = ($4[/([NE])/,1]) || ($4[/([SW])/,1]) ? 1 : -1 - coordinates = [(($1.to_i*(36e5))+($2.to_i*(6e4))+($3.to_f*(1e3)))*hemi+(2**31)].pack("N") - (orientation ||= '') << $4[[/NS/],1] ? 'lat' : 'lon' + if Regex =~ arg && $1.to_f < 180 + m = $~ + hemi = (m[4][/[NE]/]) || (m[4][/[SW]/]) ? 1 : -1 + coordinates = [ ((m[1].to_i*(36e5)) + (m[2].to_i*(6e4)) + + (m[3].to_f*(1e3))) * hemi+(2**31) ].pack("N") + orientation = m[4][/[NS]/] ? 'lat' : 'lon' else raise ArgumentError.new("not a properly formed Coord string: " + arg) end diff --git a/test/resolv/test_resource.rb b/test/resolv/test_resource.rb index 8045bbc..b75cf67 100644 --- a/test/resolv/test_resource.rb +++ b/test/resolv/test_resource.rb @@ -19,4 +19,8 @@ def test_hash bug10857 = '[ruby-core:68128] [Bug #10857]' assert_equal(@name1.hash, @name2.hash, bug10857) end + + def test_coord + Resolv::LOC::Coord.create('1 2 1.1 N') + end end -- EW