From 2ce524db77248a88c15eb94923aea3fbf6948bfa Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 19 Aug 2016 11:51:28 -0700 Subject: [PATCH] Fix potential crash for weird %PATH% **Bug** If the %PATH% env var contains path entries which are not valid, NTVS can end up crashing in `GetPathToNodeExecutableFromEnvironment` when calling `Path.combine` **Fix** Wrap this section in a try catch block to handle these entries. --- Nodejs/Product/Nodejs/Nodejs.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Nodejs/Product/Nodejs/Nodejs.cs b/Nodejs/Product/Nodejs/Nodejs.cs index 140719cca..cce4dac8e 100644 --- a/Nodejs/Product/Nodejs/Nodejs.cs +++ b/Nodejs/Product/Nodejs/Nodejs.cs @@ -92,10 +92,12 @@ public static string GetPathToNodeExecutableFromEnvironment(string executable = // If we didn't find node.js in the registry we should look at the user's path. foreach (var dir in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { - var execPath = Path.Combine(dir, executable); - if (File.Exists(execPath)) { - return execPath; - } + try { + var execPath = Path.Combine(dir, executable); + if (File.Exists(execPath)) { + return execPath; + } + } catch (ArgumentException) { /*noop*/ } } // It wasn't in the users path. Check Program Files for the nodejs folder.