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
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ module.exports = function(path, stripTrailing) {
}
}

// preserve the leading slashes of a UNC path (`\\server\share\...`),
// consistent with the win32 namespace prefixes handled above
if (prefix === '' && len > 2 && path[0] === '\\' && path[1] === '\\' && path[2] !== '\\' && path[2] !== '/') {
path = path.slice(2);
prefix = '//';
}

var segs = path.split(/[/\\]+/);
if (stripTrailing !== false && segs[segs.length - 1] === '') {
segs.pop();
Expand Down
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,22 @@ describe('normalize-path', function() {
});
});
});
describe('windows UNC paths', function() {
var units = [
['\\\\Server01\\user\\docs\\Letter.txt', '//Server01/user/docs/Letter.txt'],
['\\\\server\\share\\file.css', '//server/share/file.css'],
['\\\\localhost\\c$\\temp\\file.txt', '//localhost/c$/temp/file.txt'],
['\\\\server\\share\\', '//server/share'],
];

units.forEach(function(unit) {
it('should preserve the leading slashes of ' + unit[0], function() {
assert.equal(normalize(unit[0]), unit[1]);
});
});

it('should keep a trailing slash when stripTrailing is false', function() {
assert.equal(normalize('\\\\server\\share\\', false), '//server/share/');
});
});
});