Skip to content

Commit 272afa5

Browse files
es128phated
authored andcommitted
feat: allow basic win32 backslash use
Even though backslashes are not supposed to be used with globs, glob-parent still did its job of separating out the glob-like sections prior to escaping functionality being added. This restores that capability for basic cases. Users will not be able to use backslashes as their path separator AND escape characters; if escapes are needed they are responsible for providing their globs with the appropriate forward-slash separators.
1 parent d23c6c8 commit 272afa5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
var path = require('path');
44
var isglob = require('is-glob');
55
var pathDirname = require('path-dirname');
6+
var isWin32 = require('os').platform() === 'win32';
67

78
module.exports = function globParent(str) {
9+
// flip windows path separators
10+
if (isWin32 && str.indexOf('/') < 0) str = str.split('\\').join('/');
11+
812
// special case for strings ending in enclosure containing path separator
913
if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';
1014

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,11 @@ describe('glob2base test patterns', function() {
162162
assert.equal(gp('ooga/{booga,sooga}/**/dooga/{eooga,fooga}'), 'ooga');
163163
});
164164
});
165+
166+
if (require('os').platform() === 'win32') {
167+
describe('technically invalid windows globs', function() {
168+
it('should manage simple globs with backslash path separator', function() {
169+
assert.equal(gp('C:\\path\\*.js'), 'C:/path')
170+
});
171+
});
172+
}

0 commit comments

Comments
 (0)