From 35e018e5a5270b6a5ee503a88165e28157133ecf Mon Sep 17 00:00:00 2001 From: Andrew Glick <17516195+Antyos@users.noreply.github.com> Date: Sat, 28 Mar 2020 14:18:32 -0500 Subject: [PATCH] Fixed not working for absolute path on windows --- lib/command-exists.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/command-exists.js b/lib/command-exists.js index 2230e18..7c37ca3 100644 --- a/lib/command-exists.js +++ b/lib/command-exists.js @@ -62,7 +62,8 @@ var commandExistsUnix = function(commandName, cleanedCommandName, callback) { } var commandExistsWindows = function(commandName, cleanedCommandName, callback) { - if (/[\x00-\x1f<>:"\|\?\*]/.test(commandName)) { + // Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator + if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) { callback(null, false); return; } @@ -93,7 +94,8 @@ var commandExistsUnixSync = function(commandName, cleanedCommandName) { } var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) { - if (/[\x00-\x1f<>:"\|\?\*]/.test(commandName)) { + // Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator + if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) { return false; } try {