From c4e5fde3629f386ab73453b9d5e85f071da1fc55 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 24 Jun 2014 23:18:00 -0400 Subject: [PATCH] child_process: copy spawnSync() cwd option to proper buffer The spawnSync() cwd option was being copied to the incorrect location. This commit copies to the correct location. Closes #7824 Signed-off-by: Fedor Indutny --- src/spawn_sync.cc | 2 +- test/simple/test-child-process-execsync.js | 16 ++++++++++++++++ test/simple/test-child-process-spawnsync.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 29de6862d5..59de8d4630 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -726,7 +726,7 @@ int SyncProcessRunner::ParseOptions(Local js_value) { Local js_cwd = js_options->Get(env()->cwd_string()); if (IsSet(js_cwd)) { - r = CopyJsString(js_cwd, &uv_process_options_.cwd); + r = CopyJsString(js_cwd, &cwd_buffer_); if (r < 0) return r; uv_process_options_.cwd = cwd_buffer_; diff --git a/test/simple/test-child-process-execsync.js b/test/simple/test-child-process-execsync.js index 101ac4fcc7..6f17ab31e7 100644 --- a/test/simple/test-child-process-execsync.js +++ b/test/simple/test-child-process-execsync.js @@ -80,3 +80,19 @@ assert.deepEqual(ret, msgBuf); ret = execFileSync(process.execPath, args, { encoding: 'utf8' }); assert.strictEqual(ret, msg + '\n', 'execFileSync encoding result should match'); + +// Verify that the cwd option works - GH #7824 +(function() { + var response; + var cwd; + + if (process.platform === 'win32') { + cwd = 'c:\\'; + response = execSync('echo %cd%', {cwd: cwd}); + } else { + cwd = '/'; + response = execSync('pwd', {cwd: cwd}); + } + + assert.strictEqual(response.toString().trim(), cwd); +})(); diff --git a/test/simple/test-child-process-spawnsync.js b/test/simple/test-child-process-spawnsync.js index a8c1f592bd..a7cbb8d1df 100644 --- a/test/simple/test-child-process-spawnsync.js +++ b/test/simple/test-child-process-spawnsync.js @@ -46,3 +46,19 @@ assert.strictEqual(stop[0], 1, 'sleep should not take longer or less than 1 seco // Error test when command does not exist var ret_err = spawnSync('command_does_not_exist'); assert.strictEqual(ret_err.error.code, 'ENOENT'); + +// Verify that the cwd option works - GH #7824 +(function() { + var response; + var cwd; + + if (process.platform === 'win32') { + cwd = 'c:\\'; + response = spawnSync('cmd.exe', ['/c', 'cd'], {cwd: cwd}); + } else { + cwd = '/'; + response = spawnSync('pwd', [], {cwd: cwd}); + } + + assert.strictEqual(response.stdout.toString().trim(), cwd); +})();