Skip to content

Commit

Permalink
feat: allow basic win32 backslash use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
es128 authored and phated committed Jan 27, 2021
1 parent d23c6c8 commit 272afa5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
var path = require('path');
var isglob = require('is-glob');
var pathDirname = require('path-dirname');
var isWin32 = require('os').platform() === 'win32';

module.exports = function globParent(str) {
// flip windows path separators
if (isWin32 && str.indexOf('/') < 0) str = str.split('\\').join('/');

// special case for strings ending in enclosure containing path separator
if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';

Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ describe('glob2base test patterns', function() {
assert.equal(gp('ooga/{booga,sooga}/**/dooga/{eooga,fooga}'), 'ooga');
});
});

if (require('os').platform() === 'win32') {
describe('technically invalid windows globs', function() {
it('should manage simple globs with backslash path separator', function() {
assert.equal(gp('C:\\path\\*.js'), 'C:/path')
});
});
}

0 comments on commit 272afa5

Please sign in to comment.