From 90e2253dcae012c8f528b193ad29d9ce81852164 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 5 Apr 2026 14:14:10 +0900 Subject: [ruby/resolv] Fix `Resolv::LOC::Coord` hemisphere calculation Fix `Resolv::LOC::Coord.create` hemisphere handling for LOC coordinates. `hemi` was always `1` because `m[4]` matched `([NESW])`. https://github.com/ruby/resolv/commit/043b5bf624 --- test/resolv/test_resource.rb | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/resolv/test_resource.rb b/test/resolv/test_resource.rb index 434380236e..93c9946ccf 100644 --- a/test/resolv/test_resource.rb +++ b/test/resolv/test_resource.rb @@ -20,10 +20,6 @@ class TestResolvResource < Test::Unit::TestCase assert_equal(@name1.hash, @name2.hash, bug10857) end - def test_coord - Resolv::LOC::Coord.create('1 2 1.1 N') - end - def test_srv_no_compress # Domain name in SRV RDATA should not be compressed issue29 = 'https://github.com/ruby/resolv/issues/29' @@ -33,6 +29,31 @@ class TestResolvResource < Test::Unit::TestCase end end +class TestResolvResourceLOC < Test::Unit::TestCase + def test_coord + assert_coord('1 2 1.1 N', 'lat', 0x8038c78c) + assert_coord('42 21 43.952 N', 'lat', 0x89170690) + assert_coord('71 5 6.344 W', 'lon', 0x70bf2dd8) + assert_coord('52 14 05.000 N', 'lat', 0x8b3556c8) + assert_coord('90 0 0.000 N', 'lat', 0x934fd900) + assert_coord('90 0 0.000 S', 'lat', 0x6cb02700) + assert_coord('00 8 50.000 E', 'lon', 0x80081650) + assert_coord('0 8 50.001 E', 'lon', 0x80081651) + assert_coord('32 07 19.000 S', 'lat', 0x791b7d28) + assert_coord('116 02 25.000 E', 'lon', 0x98e64868) + assert_coord('116 02 25.000 W', 'lon', 0x6719b798) + assert_raise(ArgumentError) {Resolv::LOC::Coord.create('180 0 0.001 E')} + assert_raise(ArgumentError) {Resolv::LOC::Coord.create('180 0 0.001 W')} + end + + private def assert_coord(input, orientation, coordinate) + coord = Resolv::LOC::Coord.create(input) + + assert_equal(orientation, coord.orientation) + assert_equal([coordinate].pack("N"), coord.coordinates) + end +end + class TestResolvResourceCAA < Test::Unit::TestCase def test_caa_roundtrip raw_msg = "\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x03new\x07example\x03com\x00\x01\x01\x00\x01\x00\x00\x00\x00\x00\x16\x00\x05issueca1.example.net\xC0\x0C\x01\x01\x00\x01\x00\x00\x00\x00\x00\x0C\x80\x03tbsUnknown".b -- cgit v1.2.3