Skip to content

Commit

Permalink
Fixed not working for absolute path on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Antyos committed Mar 28, 2020
1 parent 33b3a6c commit 35e018e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/command-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 35e018e

Please sign in to comment.