diff options
author | Jason Ginchereau <jasongin@microsoft.com> | 2016-09-14 15:07:49 -0700 |
---|---|---|
committer | Ilkka Myller <ilkka.myller@nodefield.com> | 2016-09-24 01:14:56 +0300 |
commit | 0f2f8efdde82f08e043a4f1a301ae099aa7ee5f8 (patch) | |
tree | 0865fd44fcd4fd300ceb42787e85c78106782311 /test/parallel/test-path.js | |
parent | 5cb5b1f8c4b67d31d977cee66cb07adaa4acb25f (diff) | |
download | android-node-v8-0f2f8efdde82f08e043a4f1a301ae099aa7ee5f8.tar.gz android-node-v8-0f2f8efdde82f08e043a4f1a301ae099aa7ee5f8.tar.bz2 android-node-v8-0f2f8efdde82f08e043a4f1a301ae099aa7ee5f8.zip |
path: fallback to process cwd when resolving drive cwd
The `path.resolve()` function when given just a drive letter such as
"C:" tries to get a drive-specific CWD, but that isn't available in
cases when the process is not launched via cmd.exe and the process
CWD has not been explicitly set on that drive.
This change adds a fallback to the process CWD, if the process CWD
happens to be on the resolved drive letter. If the process CWD is on
another drive, then a drive-specific CWD cannot be resolved and
defaults to the drive's root as before.
Based on experimentation, the fixed behavior matches that of other
similar path resolution implementations on Windows I checked: .NET's
`System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`.
In the automated path test cases the issue doesn't occur when the
tests are run normally from cmd.exe. But it did cause an assertion
when running the tests from PowerShell, that is fixed by this change.
PR-URL: https://github.com/nodejs/node/pull/8541
Fixes: https://github.com/nodejs/node/issues/7215
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-path.js')
-rw-r--r-- | test/parallel/test-path.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/parallel/test-path.js b/test/parallel/test-path.js index 2c6d1e8f02..0a12b5ce92 100644 --- a/test/parallel/test-path.js +++ b/test/parallel/test-path.js @@ -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; @@ -444,6 +445,17 @@ resolveTests.forEach(function(test) { }); assert.strictEqual(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.strictEqual(path.win32.isAbsolute('/'), true); |