From 5a0885afa39a45ca7c2c67e369b3fb7309e048a7 Mon Sep 17 00:00:00 2001 From: Pat Leamon Date: Tue, 19 Jun 2012 13:50:02 +1000 Subject: [PATCH 1/2] Check there is a region name before trying to set it in the hash --- geoip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/geoip.c b/geoip.c index 085f6e1..5991216 100644 --- a/geoip.c +++ b/geoip.c @@ -117,6 +117,7 @@ static VALUE generic_single_value_lookup_response(char *key, char *value) VALUE rb_city_record_to_hash(GeoIPRecord *record) { VALUE hash = rb_hash_new(); + char * region_name; if(record->country_code) rb_hash_sset(hash, "country_code", encode_to_utf8_and_return_rb_str(record->country_code)); @@ -126,7 +127,9 @@ VALUE rb_city_record_to_hash(GeoIPRecord *record) rb_hash_sset(hash, "country_name", encode_to_utf8_and_return_rb_str(record->country_name)); if(record->region) { rb_hash_sset(hash, "region", encode_to_utf8_and_return_rb_str(record->region)); - rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(GeoIP_region_name_by_code(record->country_code, record->region))); + region_name = GeoIP_region_name_by_code(record->country_code, record->region); + if(region_name) + rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(region_name)); } if(record->city) rb_hash_sset(hash, "city", encode_to_utf8_and_return_rb_str(record->city)); From 8284bd9927e809b1c0809e706305f82dfd2c3f45 Mon Sep 17 00:00:00 2001 From: Pat Leamon Date: Tue, 19 Jun 2012 14:00:10 +1000 Subject: [PATCH 2/2] Add a testcase for singapore, which doesn't have a region name --- test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.rb b/test.rb index 31938c8..81e5fca 100644 --- a/test.rb +++ b/test.rb @@ -120,6 +120,11 @@ def test_character_encoding_converted_to_utf8_first assert_look_up(db, '201.85.50.148', :city, 'São Paulo') end + def test_country_without_region_name + db = GeoIP::City.new(@dbfile, :filesystem, true) + assert_look_up(db, '203.126.188.238', :city, 'Singapore') + end + end class GeoIPOrgTest < Test::Unit::TestCase