Add explorer check using SystemRoot path

Closes #4551
This commit is contained in:
Kevin Sawicki 2014-12-18 17:18:42 -08:00
parent d9e414af27
commit 2f334979d5
2 changed files with 35 additions and 3 deletions

View File

@ -1,4 +1,5 @@
BufferedProcess = require '../src/buffered-process' BufferedProcess = require '../src/buffered-process'
ChildProcess = require 'child_process'
describe "BufferedProcess", -> describe "BufferedProcess", ->
describe "when a bad command is specified", -> describe "when a bad command is specified", ->
@ -40,3 +41,26 @@ describe "BufferedProcess", ->
expect(window.onerror).toHaveBeenCalled() expect(window.onerror).toHaveBeenCalled()
expect(window.onerror.mostRecentCall.args[0]).toContain 'Failed to spawn command `bad-command-nope`' expect(window.onerror.mostRecentCall.args[0]).toContain 'Failed to spawn command `bad-command-nope`'
expect(window.onerror.mostRecentCall.args[4].name).toBe 'BufferedProcessError' expect(window.onerror.mostRecentCall.args[4].name).toBe 'BufferedProcessError'
describe "when the explorer command is spawned on Windows", ->
originalPlatform = null
beforeEach ->
# Prevent any commands from actually running and affecting the host
originalSpawn = ChildProcess.spawn
spyOn(ChildProcess, 'spawn').andCallFake ->
# Just spawn something that won't actually modify the host
if originalPlatform is 'win32'
originalSpawn('dir')
else
originalSpawn('ls')
originalPlatform = process.platform
Object.defineProperty process, 'platform', value: 'win32'
afterEach ->
Object.defineProperty process, 'platform', value: originalPlatform
it "doesn't quote arguments of the form /root,C...", ->
new BufferedProcess({command: 'explorer.exe', args: ['/root,C:\\foo']})
expect(ChildProcess.spawn.argsForCall[0][1][2]).toBe '"explorer.exe /root,C:\\foo"'

View File

@ -47,12 +47,12 @@ class BufferedProcess
@emitter = new Emitter @emitter = new Emitter
options ?= {} options ?= {}
# Related to joyent/node#2318 # Related to joyent/node#2318
if process.platform is "win32" if process.platform is 'win32'
# Quote all arguments and escapes inner quotes # Quote all arguments and escapes inner quotes
if args? if args?
cmdArgs = args.filter (arg) -> arg? cmdArgs = args.filter (arg) -> arg?
cmdArgs = cmdArgs.map (arg) -> cmdArgs = cmdArgs.map (arg) =>
if command in ['explorer.exe', 'explorer'] and /^\/[a-zA-Z]+,.*$/.test(arg) if @isExplorerCommand(command) and /^\/[a-zA-Z]+,.*$/.test(arg)
# Don't wrap /root,C:\folder style arguments to explorer calls in # Don't wrap /root,C:\folder style arguments to explorer calls in
# quotes since they will not be interpreted correctly if they are # quotes since they will not be interpreted correctly if they are
arg arg
@ -191,6 +191,14 @@ class BufferedProcess
@process?.kill() @process?.kill()
@process = null @process = null
isExplorerCommand: (command) ->
if command is 'explorer.exe' or command is 'explorer'
true
else if process.env.SystemRoot
command is path.join(process.env.SystemRoot, 'explorer.exe') or command is path.join(process.env.SystemRoot, 'explorer')
else
false
# Public: Terminate the process. # Public: Terminate the process.
kill: -> kill: ->
return if @killed return if @killed