Skip to content

Commit 143749e

Browse files
authored
Merge pull request #1392 from plotly/country-regex-update
Country regex update
2 parents d8441a0 + a2eb6bb commit 143749e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"alpha-shape": "^1.0.0",
5454
"arraytools": "^1.0.0",
5555
"convex-hull": "^1.0.3",
56-
"country-regex": "^1.0.0",
56+
"country-regex": "^1.1.0",
5757
"d3": "^3.5.12",
5858
"delaunay-triangulate": "^1.1.6",
5959
"es6-promise": "^3.0.2",

src/lib/geo_location_utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function countryNameToISO3(countryName) {
5151
var iso3 = countryIds[i],
5252
regex = new RegExp(countryRegex[iso3]);
5353

54-
if(regex.test(countryName.toLowerCase())) return iso3;
54+
if(regex.test(countryName.trim().toLowerCase())) return iso3;
5555
}
5656

5757
Lib.warn('Unrecognized country name: ' + countryName + '.');

test/jasmine/tests/geo_test.js

+19
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,25 @@ describe('geojson / topojson utils', function() {
380380
expect(out).toEqual(false);
381381
});
382382
});
383+
384+
describe('should distinguish between US and US Virgin Island', function() {
385+
386+
// N.B. Virgin Island don't appear at the 'world_110m' resolution
387+
var topojsonName = 'world_50m';
388+
var topojson = GeoAssets.topojson[topojsonName];
389+
390+
var shouldPass = [
391+
'Virgin Islands (U.S.)',
392+
' Virgin Islands (U.S.) '
393+
];
394+
395+
shouldPass.forEach(function(str) {
396+
it('(case ' + str + ')', function() {
397+
var out = _locationToFeature(topojson, str, 'country names');
398+
expect(out.id).toEqual('VIR');
399+
});
400+
});
401+
});
383402
});
384403

385404
describe('Test geo interactions', function() {

0 commit comments

Comments
 (0)