dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH v3] resolv: attempt to fix Resolv::LOC::Coord.create
@ 2015-12-31 19:23 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-12-31 19:23 UTC (permalink / raw)
  To: spew

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-31 19:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-31 19:23 [PATCH v3] resolv: attempt to fix Resolv::LOC::Coord.create Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).