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)); 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