diff --git a/package.json b/package.json index 6496482fa12..c61b658b320 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "alpha-shape": "^1.0.0", "arraytools": "^1.0.0", "convex-hull": "^1.0.3", - "country-regex": "^1.0.0", + "country-regex": "^1.1.0", "d3": "^3.5.12", "delaunay-triangulate": "^1.1.6", "es6-promise": "^3.0.2", diff --git a/src/lib/geo_location_utils.js b/src/lib/geo_location_utils.js index 30795820c37..b896e03f842 100644 --- a/src/lib/geo_location_utils.js +++ b/src/lib/geo_location_utils.js @@ -51,7 +51,7 @@ function countryNameToISO3(countryName) { var iso3 = countryIds[i], regex = new RegExp(countryRegex[iso3]); - if(regex.test(countryName.toLowerCase())) return iso3; + if(regex.test(countryName.trim().toLowerCase())) return iso3; } Lib.warn('Unrecognized country name: ' + countryName + '.'); diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index 244db755d2c..43ae0566de4 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -380,6 +380,25 @@ describe('geojson / topojson utils', function() { expect(out).toEqual(false); }); }); + + describe('should distinguish between US and US Virgin Island', function() { + + // N.B. Virgin Island don't appear at the 'world_110m' resolution + var topojsonName = 'world_50m'; + var topojson = GeoAssets.topojson[topojsonName]; + + var shouldPass = [ + 'Virgin Islands (U.S.)', + ' Virgin Islands (U.S.) ' + ]; + + shouldPass.forEach(function(str) { + it('(case ' + str + ')', function() { + var out = _locationToFeature(topojson, str, 'country names'); + expect(out.id).toEqual('VIR'); + }); + }); + }); }); describe('Test geo interactions', function() {