Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6cc4cc6

Browse files
committed
explore: escape args properly on Windows Bash
Despite being bash, Node.js running on windows git mingw bash still executes child processes using cmd.exe. As a result, arguments in this environment need to be escaped in the style of cmd.exe, not bash.
1 parent bf93e91 commit 6cc4cc6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/explore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ var npm = require('./npm.js')
99
var spawn = require('./utils/spawn')
1010
var path = require('path')
1111
var fs = require('graceful-fs')
12-
var isWindowsShell = require('./utils/is-windows-shell.js')
12+
var isWindows = require('./utils/is-windows.js')
1313
var escapeExecPath = require('./utils/escape-exec-path.js')
1414
var escapeArg = require('./utils/escape-arg.js')
1515
var output = require('./utils/output.js')
16+
var log = require('npmlog')
1617

1718
function explore (args, cb) {
1819
if (args.length < 1 || !args[0]) return cb(explore.usage)
@@ -23,7 +24,7 @@ function explore (args, cb) {
2324

2425
var shellArgs = []
2526
if (args) {
26-
if (isWindowsShell) {
27+
if (isWindows) {
2728
var execCmd = escapeExecPath(args.shift())
2829
var execArgs = [execCmd].concat(args.map(escapeArg))
2930
opts.windowsVerbatimArguments = true
@@ -49,6 +50,7 @@ function explore (args, cb) {
4950
)
5051
}
5152

53+
log.silly('explore', {sh, shellArgs, opts})
5254
var shell = spawn(sh, shellArgs, opts)
5355
shell.on('close', function (er) {
5456
// only fail if non-interactive.

lib/utils/escape-arg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
var path = require('path')
3-
var isWindowsShell = require('./is-windows-shell.js')
3+
var isWindows = require('./is-windows.js')
44

55
/*
66
Escape the name of an executable suitable for passing to the system shell.
@@ -15,7 +15,7 @@ any single quotes in the filename.
1515
module.exports = escapify
1616

1717
function escapify (str) {
18-
if (isWindowsShell) {
18+
if (isWindows) {
1919
return '"' + path.normalize(str) + '"'
2020
} else {
2121
if (/[^-_.~/\w]/.test(str)) {

lib/utils/escape-exec-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
var path = require('path')
3-
var isWindowsShell = require('./is-windows-shell.js')
3+
var isWindows = require('./is-windows.js')
44

55
/*
66
Escape the name of an executable suitable for passing to the system shell.
@@ -20,7 +20,7 @@ function windowsQuotes (str) {
2020
}
2121

2222
function escapify (str) {
23-
if (isWindowsShell) {
23+
if (isWindows) {
2424
return path.normalize(str).split(/\\/).map(windowsQuotes).join('\\')
2525
} else if (/[^-_.~/\w]/.test(str)) {
2626
return "'" + str.replace(/'/g, "'\"'\"'") + "'"

0 commit comments

Comments
 (0)