From 272afa5fd070fc0f796386a5993d4ee4a846988b Mon Sep 17 00:00:00 2001 From: Elan Shanker Date: Wed, 16 Nov 2016 10:53:55 -0500 Subject: [PATCH] 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. --- index.js | 4 ++++ test.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/index.js b/index.js index 91a863e..3a14a53 100644 --- a/index.js +++ b/index.js @@ -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 += '/'; diff --git a/test.js b/test.js index 92f194a..2b9f212 100644 --- a/test.js +++ b/test.js @@ -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') + }); + }); +}