Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
3edd272
test: add common.noop, default for common.mustCall()
jasnell Mar 24, 2017
2d96b01
tools: add rule prefering common.mustNotCall()
jasnell Mar 24, 2017
ce86b8e
test: add mustCallAtLeast
refack May 9, 2017
189dc42
test: harden test-dgram-bind-shared-ports
refack May 18, 2017
a28f7a2
dns: fix `resolve` failed starts without network
XadillaX Aug 10, 2017
cb3b866
src: supply missing comments for CLI options
sam-github Apr 5, 2017
1576c09
src: use option parser for expose_internals
sam-github Apr 5, 2017
ee98df8
test: mark test-fs-read-buffer-to-string-fail as flaky
Jeyanthinath Jul 26, 2017
3f2b8a9
test: increase coverage for path.parse
tniessen Jul 24, 2017
ba411f1
path: fix win32 volume-relative paths
TimothyGu Jul 24, 2017
d75363b
path: remove unnecessary string copies
tniessen Jul 23, 2017
cbd2c77
tools: add missing #include "unicode/putil.h"
srl295 Mar 27, 2017
0f36025
timers: do not use user object call/apply
Trott May 11, 2017
c7622e1
deps: cherry-pick f5fad6d from upstream v8
danbev May 2, 2017
2914926
src: only call FatalException if not verbose
danbev May 3, 2017
9dde328
build: reduce one level of spawning in node_gyp
refack Apr 25, 2017
4072073
test: check number of message events
Trott May 20, 2017
548aba4
test: confirm callback is invoked in fs test
Trott May 20, 2017
4442a1f
test: check noop function invocations
Trott May 21, 2017
85a8d6e
test: simplify assert usage in test-stream2-basic
Trott May 21, 2017
10ad128
test: move stream2 test from pummel to parallel
Trott May 21, 2017
8fd7fcc
build: support dtrace on ARM
bradleythughes Mar 27, 2017
6ca963a
test: replace `indexOf` with `includes`
thelostone-mc May 25, 2017
b997b8f
test: use mustNotCall() in test-stream2-objects
Trott May 26, 2017
7919eee
test: use mustCall() in test-readline-interface
Trott May 27, 2017
089bd3b
test: refactor test-net-server-bind
Trott May 29, 2017
30201e5
test: add documentation for common.mustNotCall()
Trott Jun 1, 2017
7c2befc
test: refactor test-dgram-oob-buffer
Trott Jun 3, 2017
c15393c
test: check callback not invoked on lookup error
Trott Jun 4, 2017
1a95a51
test: refactor domain tests
Trott Jun 5, 2017
8033cf3
test: refactor test-fs-read-*
Trott Jun 6, 2017
bfea6b2
src: merge `fn_name` in NODE_SET_PROTOTYPE_METHOD
XadillaX Jun 8, 2017
245f6b0
test: use mustNotCall in test-http-eof-on-connect
Trott Jun 9, 2017
6f44563
test: add mustCall() to child-process test
Trott Jun 11, 2017
2f8aa88
test: use mustNotCall() in test-fs-watch
Trott Jun 10, 2017
9a9d493
test: make test-http(s)-set-timeout-server alike
jklepatch Jun 12, 2017
8fd5297
test: refactor test-http-set-timeout-server
Trott Jun 19, 2017
9fd05e4
test: remove needless RegExp flags
vsemozhetbyt Jun 15, 2017
ade84b4
test: use string instead of RegExp in split()
vsemozhetbyt Jun 16, 2017
ed2a8d1
doc: add missing zlib link to stream API docs
Rob--W Jun 21, 2017
1132754
test: remove unnecessary Buffer import
swinston1000 Jun 21, 2017
0925c8e
test: remove require('buffer') on 6 fs test files
sallen450 Jun 21, 2017
4449faa
test: remove require('buffer') from 4 buffer tests
OriLev Jun 21, 2017
2cb4243
test: remove `require('buffer')` from 4 test files
leizongmin Jun 21, 2017
846c10c
test: remove unnecessary require('buffer').Buffer
lenakaplan Jun 21, 2017
ea2a7f8
test: remove `require('buffer')` from 4 test files
XadillaX Jun 21, 2017
3ebe458
build: clean up config_fips.gypi
danbev Jun 21, 2017
73ba423
test: make http(s)-set-timeout-server more similar
jklepatch Jun 20, 2017
16998a1
test: refactor test-tls-env-extra-ca
Trott Jun 23, 2017
772927e
test: refactor test-tls-invoked-queued
Trott Jun 23, 2017
7a2de19
test: skip fips tests using OpenSSL config file
danbev Jun 18, 2017
1a50b56
doc: fixed formatting issue in cli docs
Jun 20, 2017
059e9ad
test: remove unneeded HandleScope usage
ezequielgarcia Jun 19, 2017
4cfc47e
doc: fix mistake in path.relative
tniessen Jun 25, 2017
17230b0
doc: add gireeshpunathil to collaborators
gireeshpunathil Jun 28, 2017
92850c3
doc: add @nodejs/documentation to CC table
vsemozhetbyt Jun 27, 2017
0cb7bab
tools: remove comment in eslint rule
danbev Jun 27, 2017
5865268
test: refactor test-cluster-basic
Trott Jun 25, 2017
a8901e5
doc: note that fs.futimes only works on AIX >7.1
gibfahn Jun 13, 2017
42b825b
src: add missing new line to printed message
TimothyGu Jun 26, 2017
97ad485
test: refactor test-child-process-send-type-error
Trott Jun 25, 2017
375c274
src: move crypto_bio/clienthello to crypto ns
danbev Jun 28, 2017
600d009
lib: fix typos
BridgeAR Jun 17, 2017
e0119c5
test: refactor test-fs-watchfile
Trott Jun 16, 2017
47e38ac
child_process: fix handleless NODE_HANDLE handling
santigimeno May 25, 2017
ebb4b81
test: remove undef NDEBUG from at-exit addons test
danbev Jun 30, 2017
2a2db02
test: replace indexOf with includes and startsWith
Jun 21, 2017
7a0aedb
doc: fix example in child_process.md
rus0000 Jun 16, 2017
30e9df7
test: refactor test-http-invalidheaderfield
Trott Jun 30, 2017
5d23670
doc: add CTC members to Collaborators list
Trott May 29, 2017
6b3f8da
test: refactor test-http(s)-set-timeout-server
aqrln Jun 26, 2017
f9a472f
test,fs: delay unlink in test-regress-GH-4027.js
jaimecbernardo Jun 30, 2017
53f5e52
test: fix require nits in some test-tls-* tests
vsemozhetbyt Jun 30, 2017
ce28385
doc, util, console: clarify ambiguous docs
nattelog Jul 1, 2017
13d0450
tools: use no-use-before-define ESLint rule
vsemozhetbyt Jul 1, 2017
57cc027
test: fix flaky test-https-set-timeout-server
Trott Jul 8, 2017
cc51087
test: fix flaky http(s)-set-server-timeout tests
Trott Jul 20, 2017
199af21
v8: handle proxy objects in MakeMirror(), v1
bnoordhuis Jul 24, 2017
cebce8b
v8: handle proxy objects in MakeMirror(), v2
bnoordhuis Jul 24, 2017
5663961
build,windows: implement PEP514 python detection
refack Jun 24, 2017
c6fa2c5
build,windows: restore DISTTYPEDIR
refack Jun 28, 2017
ed690ba
build,win: fix python detection script
jasongin Jul 31, 2017
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
Prev Previous commit
Next Next commit
path: fix win32 volume-relative paths
`path.resolve()` and `path.join()` are left alone in this commit due to
the lack of clear semantics.

Backport-PR-URL: #14787
PR-URL: #14440
Fixes: #14405
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
TimothyGu authored and MylesBorins committed Aug 14, 2017
commit ba411f1e9b321ee42588978d65243c5451bef400
45 changes: 25 additions & 20 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,28 @@ const win32 = {

extname: function extname(path) {
assertPath(path);
var start = 0;
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {

// Check for a drive letter prefix so as not to mistake the following
// path separator as an extra separator at the end of the path that can be
// disregarded
if (path.length >= 2) {
const code = path.charCodeAt(0);
if (path.charCodeAt(1) === 58/*:*/ &&
((code >= 65/*A*/ && code <= 90/*Z*/) ||
(code >= 97/*a*/ && code <= 122/*z*/))) {
start = startPart = 2;
}
}

for (var i = path.length - 1; i >= start; --i) {
const code = path.charCodeAt(i);
if (code === 47/*/*/ || code === 92/*\*/) {
// If we reached a path separator that was not part of a set of path
Expand Down Expand Up @@ -956,15 +970,12 @@ const win32 = {
var len = path.length;
var rootEnd = 0;
var code = path.charCodeAt(0);
var isAbsolute = false;

// Try to match a root
if (len > 1) {
if (code === 47/*/*/ || code === 92/*\*/) {
// Possible UNC root

isAbsolute = true;

code = path.charCodeAt(1);
rootEnd = 1;
if (code === 47/*/*/ || code === 92/*\*/) {
Expand Down Expand Up @@ -1023,7 +1034,6 @@ const win32 = {
ret.root = ret.dir = path.slice(0, 3);
return ret;
}
isAbsolute = true;
rootEnd = 3;
}
} else {
Expand All @@ -1045,7 +1055,7 @@ const win32 = {
ret.root = path.slice(0, rootEnd);

var startDot = -1;
var startPart = 0;
var startPart = rootEnd;
var end = -1;
var matchedSlash = true;
var i = path.length - 1;
Expand Down Expand Up @@ -1094,26 +1104,21 @@ const win32 = {
startDot === end - 1 &&
startDot === startPart + 1)) {
if (end !== -1) {
if (startPart === 0 && isAbsolute)
ret.base = ret.name = path.slice(rootEnd, end);
else
ret.base = ret.name = path.slice(startPart, end);
ret.base = ret.name = path.slice(startPart, end);
}
} else {
if (startPart === 0 && isAbsolute) {
ret.name = path.slice(rootEnd, startDot);
ret.base = path.slice(rootEnd, end);
} else {
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
}
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
ret.ext = path.slice(startDot, end);
}

if (startPart > 0)
// If the directory is the root, use the entire root as the `dir` including
// the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
// trailing slash (`C:\abc\def` -> `C:\abc`).
if (startPart > 0 && startPart !== rootEnd)
ret.dir = path.slice(0, startPart - 1);
else if (isAbsolute)
ret.dir = path.slice(0, rootEnd);
else
ret.dir = ret.root;

return ret;
},
Expand Down
82 changes: 45 additions & 37 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ const assert = require('assert');
const path = require('path');

const winPaths = [
'C:\\path\\dir\\index.html',
'C:\\another_path\\DIR\\1\\2\\33\\\\index',
'another_path\\DIR with spaces\\1\\2\\33\\index',
'\\foo\\C:',
'file',
'.\\file',
'C:\\',
'C:',
'\\',
'',
// [path, root]
['C:\\path\\dir\\index.html', 'C:\\'],
['C:\\another_path\\DIR\\1\\2\\33\\\\index', 'C:\\'],
['another_path\\DIR with spaces\\1\\2\\33\\index', ''],
['\\', '\\'],
['\\foo\\C:', '\\'],
['file', ''],
['file:stream', ''],
['.\\file', ''],
['C:', 'C:'],
['C:.', 'C:'],
['C:..', 'C:'],
['C:abc', 'C:'],
['C:\\', 'C:\\'],
['C:\\abc', 'C:\\' ],
['', ''],

// unc
'\\\\server\\share\\file_path',
'\\\\server two\\shared folder\\file path.zip',
'\\\\teela\\admin$\\system32',
'\\\\?\\UNC\\server\\share'
['\\\\server\\share\\file_path', '\\\\server\\share\\'],
['\\\\server two\\shared folder\\file path.zip',
'\\\\server two\\shared folder\\'],
['\\\\teela\\admin$\\system32', '\\\\teela\\admin$\\'],
['\\\\?\\UNC\\server\\share', '\\\\?\\UNC\\']
];

const winSpecialCaseParseTests = [
['/foo/bar', { root: '/' }],
['C:', { root: 'C:', dir: 'C:', base: '' }],
['C:\\', { root: 'C:\\', dir: 'C:\\', base: '' }]
];

const winSpecialCaseFormatTests = [
Expand All @@ -39,26 +44,27 @@ const winSpecialCaseFormatTests = [
];

const unixPaths = [
'/home/user/dir/file.txt',
'/home/user/a dir/another File.zip',
'/home/user/a dir//another&File.',
'/home/user/a$$$dir//another File.zip',
'user/dir/another File.zip',
'file',
'.\\file',
'./file',
'C:\\foo',
'/',
'',
'.',
'..',
'/foo',
'/foo.',
'/foo.bar',
'/.',
'/.foo',
'/.foo.bar',
'/foo/bar.baz',
// [path, root]
['/home/user/dir/file.txt', '/'],
['/home/user/a dir/another File.zip', '/'],
['/home/user/a dir//another&File.', '/'],
['/home/user/a$$$dir//another File.zip', '/'],
['user/dir/another File.zip', ''],
['file', ''],
['.\\file', ''],
['./file', ''],
['C:\\foo', ''],
['/', '/'],
['', ''],
['.', ''],
['..', ''],
['/foo', '/'],
['/foo.', '/'],
['/foo.bar', '/'],
['/.', '/'],
['/.foo', '/'],
['/.foo.bar', '/'],
['/foo/bar.baz', '/']
];

const unixSpecialCaseFormatTests = [
Expand Down Expand Up @@ -169,14 +175,16 @@ function checkErrors(path) {
}

function checkParseFormat(path, paths) {
paths.forEach(function(element) {
paths.forEach(function([element, root]) {
const output = path.parse(element);
assert.strictEqual(typeof output.root, 'string');
assert.strictEqual(typeof output.dir, 'string');
assert.strictEqual(typeof output.base, 'string');
assert.strictEqual(typeof output.ext, 'string');
assert.strictEqual(typeof output.name, 'string');
assert.strictEqual(path.format(output), element);
assert.strictEqual(output.root, root);
assert(output.dir.startsWith(output.root));
assert.strictEqual(output.dir, output.dir ? path.dirname(element) : '');
assert.strictEqual(output.base, path.basename(element));
assert.strictEqual(output.ext, path.extname(element));
Expand Down
28 changes: 27 additions & 1 deletion test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ assert.strictEqual(path.win32.basename('aaa\\bbb', 'bbb'), 'bbb');
assert.strictEqual(path.win32.basename('aaa\\bbb\\\\\\\\', 'bbb'), 'bbb');
assert.strictEqual(path.win32.basename('aaa\\bbb', 'bb'), 'b');
assert.strictEqual(path.win32.basename('aaa\\bbb', 'b'), 'bb');
assert.strictEqual(path.win32.basename('C:'), '');
assert.strictEqual(path.win32.basename('C:.'), '.');
assert.strictEqual(path.win32.basename('C:\\'), '');
assert.strictEqual(path.win32.basename('C:\\dir\\base.ext'), 'base.ext');
assert.strictEqual(path.win32.basename('C:\\basename.ext'), 'basename.ext');
assert.strictEqual(path.win32.basename('C:basename.ext'), 'basename.ext');
assert.strictEqual(path.win32.basename('C:basename.ext\\'), 'basename.ext');
assert.strictEqual(path.win32.basename('C:basename.ext\\\\'), 'basename.ext');
assert.strictEqual(path.win32.basename('C:foo'), 'foo');
assert.strictEqual(path.win32.basename('file:stream'), 'file:stream');

// On unix a backslash is just treated as any other character.
assert.strictEqual(path.posix.basename('\\dir\\basename.ext'),
Expand Down Expand Up @@ -99,6 +109,8 @@ assert.strictEqual(path.win32.dirname('c:foo\\'), 'c:');
assert.strictEqual(path.win32.dirname('c:foo\\bar'), 'c:foo');
assert.strictEqual(path.win32.dirname('c:foo\\bar\\'), 'c:foo');
assert.strictEqual(path.win32.dirname('c:foo\\bar\\baz'), 'c:foo\\bar');
assert.strictEqual(path.win32.dirname('file:stream'), '.');
assert.strictEqual(path.win32.dirname('dir\\file:stream'), 'dir');
assert.strictEqual(path.win32.dirname('\\\\unc\\share'),
'\\\\unc\\share');
assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo'),
Expand Down Expand Up @@ -166,6 +178,7 @@ assert.strictEqual(path.win32.dirname('foo'), '.');
['file./', '.'],
['file.//', '.'],
].forEach((test) => {
const expected = test[1];
[path.posix.extname, path.win32.extname].forEach((extname) => {
let input = test[0];
let os;
Expand All @@ -176,12 +189,19 @@ assert.strictEqual(path.win32.dirname('foo'), '.');
os = 'posix';
}
const actual = extname(input);
const expected = test[1];
const message = `path.${os}.extname(${JSON.stringify(input)})\n expect=${
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
if (actual !== expected)
failures.push(`\n${message}`);
});
{
const input = `C:${test[0].replace(slashRE, '\\')}`;
const actual = path.win32.extname(input);
const message = `path.win32.extname(${JSON.stringify(input)})\n expect=${
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
if (actual !== expected)
failures.push(`\n${message}`);
}
});
assert.strictEqual(failures.length, 0, failures.join(''));

Expand Down Expand Up @@ -385,6 +405,12 @@ assert.strictEqual(path.win32.normalize('a//b//.'), 'a\\b');
assert.strictEqual(path.win32.normalize('//server/share/dir/file.ext'),
'\\\\server\\share\\dir\\file.ext');
assert.strictEqual(path.win32.normalize('/a/b/c/../../../x/y/z'), '\\x\\y\\z');
assert.strictEqual(path.win32.normalize('C:'), 'C:.');
assert.strictEqual(path.win32.normalize('C:..\\abc'), 'C:..\\abc');
assert.strictEqual(path.win32.normalize('C:..\\..\\abc\\..\\def'),
'C:..\\..\\def');
assert.strictEqual(path.win32.normalize('C:\\.'), 'C:\\');
assert.strictEqual(path.win32.normalize('file:stream'), 'file:stream');

assert.strictEqual(path.posix.normalize('./fixtures///b/../b/c.js'),
'fixtures/b/c.js');
Expand Down