From 36b82a6f276ad05a455abc2a7ace2e19dd0f835a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= <etienne@plot.ly>
Date: Fri, 17 Feb 2017 14:28:33 -0500
Subject: [PATCH 1/3] bump country-regex version

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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",

From ee7de47ea09898605025511b61e7ad0da6fe6e04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= <etienne@plot.ly>
Date: Fri, 17 Feb 2017 14:31:00 -0500
Subject: [PATCH 2/3] trim country name string before regex test

- to extract sure (!)
- as by design, the country name regex don't strip leading
  or trailing whitespaces see:
  https://github.com/vincentarelbundock/countrycode/pull/134#issuecomment-280270377
---
 src/lib/geo_location_utils.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 + '.');

From a2eb6bb35ffbc08baa80f7ed9c8e7f90fccba3ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= <etienne@plot.ly>
Date: Fri, 17 Feb 2017 14:31:31 -0500
Subject: [PATCH 3/3] add test case for US Virgin Islands country name -> ISO3

---
 test/jasmine/tests/geo_test.js | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

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() {