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
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = function globParent(str, opts) {
str = str.replace(backslash, slash);
}

var win32Root = isWin32 && /^([a-zA-Z]:\/)/.exec(str);

// special case for strings ending in enclosure containing path separator
if (isEnclosure(str)) {
str += slash;
Expand All @@ -34,8 +36,12 @@ module.exports = function globParent(str, opts) {
str = pathPosixDirname(str);
} while (isGlobby(str));

// remove escape chars and return result
return str.replace(escaped, '$1');
// remove escape chars and preserve a drive root used as the parent
str = str.replace(escaped, '$1');
if (win32Root && str === win32Root[0].slice(0, -1)) {
return win32Root[0];
}
return str;
};

function isEnclosure(str) {
Expand Down
17 changes: 17 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ describe('glob2base test patterns', function () {

if (isWin32) {
describe('technically invalid windows globs', function () {
it('should preserve a drive root when it is the static parent', function (done) {
var options = { flipBackslashes: false };

expect(gp('C:/', options)).toEqual('C:/');
expect(gp('C:/.', options)).toEqual('C:/');
expect(gp('C:/*', options)).toEqual('C:/');
expect(gp('C:/./*', options)).toEqual('C:/.');
expect(gp('C://', options)).toEqual('C:/');
expect(gp('C://*', options)).toEqual('C:/');
expect(gp('C:/file.js', options)).toEqual('C:/');
expect(gp('C:/dir/*.js', options)).toEqual('C:/dir');
expect(gp('C:\\')).toEqual('C:/');
expect(gp('C:\\*')).toEqual('C:/');

done();
});

it('should manage simple globs with backslash path separator', function (done) {
expect(gp('C:\\path\\*.js')).toEqual('C:/path');

Expand Down