Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to process cwd when resolving drive cwd #8541

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ const win32 = {
} else {
// Windows has the concept of drive-specific current working
// directories. If we've resolved a drive letter but not yet an
// absolute path, get cwd for that drive. We're sure the device is not
// absolute path, get cwd for that drive, or the process cwd if
// the drive cwd is not available. We're sure the device is not
// a UNC path at this points, because UNC paths are always absolute.
path = process.env['=' + resolvedDevice];
// Verify that a drive-local cwd was found and that it actually points
path = process.env['=' + resolvedDevice] || process.cwd();

// Verify that a cwd was found and that it actually points
// to our drive. If not, default to the drive's root.
if (path === undefined ||
path.slice(0, 3).toLowerCase() !==
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/path-resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Tests resolving a path in the context of a spawned process.
// See https://github.com/nodejs/node/issues/7215
var path = require('path');
console.log(path.resolve(process.argv[2]));
12 changes: 12 additions & 0 deletions test/parallel/test-path.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const child = require('child_process');
const path = require('path');

const f = __filename;
Expand Down Expand Up @@ -440,6 +441,17 @@ resolveTests.forEach(function(test) {
});
assert.equal(failures.length, 0, failures.join(''));

if (common.isWindows) {
// Test resolving the current Windows drive letter from a spawned process.
// See https://github.com/nodejs/node/issues/7215
const currentDriveLetter = path.parse(process.cwd()).root.substring(0, 2);
const resolveFixture = path.join(common.fixturesDir, 'path-resolve.js');
var spawnResult = child.spawnSync(
process.argv[0], [resolveFixture, currentDriveLetter]);
var resolvedPath = spawnResult.stdout.toString().trim();
assert.equal(resolvedPath.toLowerCase(), process.cwd().toLowerCase());
}


// path.isAbsolute tests
assert.equal(path.win32.isAbsolute('/'), true);
Expand Down