Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ const win32 = {
} while ((index = StringPrototypeIndexOf(path, ':', index + 1)) !== -1);
}
const colonIndex = StringPrototypeIndexOf(path, ':');
if (isWindowsReservedName(path, colonIndex)) {
if (colonIndex !== -1 && isWindowsReservedName(path, colonIndex)) {
return `.\\${device ?? ''}${tail}`;
}
if (device === undefined) {
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-path-normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ assert.strictEqual(path.win32.normalize('//server/share/dir/../../../?/D:/file')
assert.strictEqual(path.win32.normalize('//server/goodshare/../badshare/file'),
'\\\\server\\goodshare\\badshare\\file');

// A path is only a Windows reserved device name when the reserved name is
// followed by a colon. A name that merely starts with a reserved name (and has
// no colon) must be left untouched and not be prefixed with `.\`.
assert.strictEqual(path.win32.normalize('CONx'), 'CONx');
assert.strictEqual(path.win32.normalize('NULs'), 'NULs');
assert.strictEqual(path.win32.normalize('LPT1x'), 'LPT1x');
assert.strictEqual(path.win32.normalize('PRNzzz'), 'PRNzzz');
assert.strictEqual(path.win32.normalize('CON'), 'CON');
// With a trailing colon the reserved-name handling still applies.
assert.strictEqual(path.win32.normalize('CON:'), '.\\CON:.');

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