forked from isaacs/node-glob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wildcards that now work: \\host\directory\* Wildcards that still don't work: \\host\* [fixes isaacs#74, isaacs#123, isaacs#146] handle UNC paths on win32 credit to @staticshock for the WinPath work
- Loading branch information
1 parent
7e59b55
commit 1f313a5
Showing
6 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var test = require("tap").test | ||
var setopts = require("../common").setopts; | ||
|
||
function stubPlatform(platform, fn) { | ||
var descriptor = Object.getOwnPropertyDescriptor(process, 'platform'); | ||
|
||
try { | ||
Object.defineProperty(process, 'platform', { | ||
value: platform, | ||
writable: false | ||
}); | ||
|
||
fn(); | ||
} finally { | ||
Object.defineProperty(process, 'platform', descriptor); | ||
} | ||
|
||
} | ||
|
||
test("unit test – setopts – ensure UNC paths are handled correctly", function (t) { | ||
|
||
stubPlatform("win32", function() { | ||
var sentinel = { } | ||
setopts(sentinel, "\\\\vmware-host\\Shared Folders\\-folder\\*", { platform: 'win32' }) | ||
t.same(sentinel.minimatch.pattern, "\\-folder\\\*") | ||
}) | ||
|
||
stubPlatform("darwin", function() { | ||
var sentinel = { } | ||
setopts(sentinel, "\\\\vmware-host\\Shared Folders\\-folder\\*", { platform: 'darwin' }) | ||
t.same(sentinel.minimatch.pattern, "\\\\vmware-host\\Shared Folders\\-folder\\*") | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
var test = require('tap').test; | ||
var glob = require('../'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
test('glob doesn\'t choke on UNC paths', function(t) { | ||
stubPlatform('win32', function(restorePlatform) { | ||
var readdir = fs.readdir; | ||
|
||
fs.readdir = function(path, cb) { | ||
if (path === '\\\\vmware-share\\share-name\\baz') { | ||
return cb(undefined, [ | ||
'some-file.txt', | ||
'some-other-file.txt' | ||
]) | ||
} | ||
|
||
readdir(path, cb) | ||
} | ||
|
||
var results = glob('\\\\vmware-share\\share-name\\baz\\*', function (er, results) { | ||
restorePlatform(); | ||
|
||
if (er) | ||
throw er | ||
|
||
t.same(results, [ | ||
'\\\\vmware-share\\share-name\\baz\\some-file.txt', | ||
'\\\\vmware-share\\share-name\\baz\\some-other-file.txt' | ||
]) | ||
|
||
t.end() | ||
}, { platform: 'win32' }) | ||
}) | ||
}) | ||
|
||
function stubPlatform(platform, fn) { | ||
var descriptor = Object.getOwnPropertyDescriptor(process, 'platform') | ||
var path = require('path'); | ||
var join = path.join; | ||
var normalize = path.normalize; | ||
var sep = path.sep; | ||
var resolve = path.resolve; | ||
var isAbsolute = require('path-is-absolute'); | ||
|
||
function restore() { | ||
path.resolve = resolve; | ||
path.sep = sep; | ||
path.join = join; | ||
path.normalize = normalize; | ||
var isAbsolute = require('path-is-absolute'); | ||
Object.defineProperty(process, 'platform', descriptor); | ||
} | ||
|
||
try { | ||
Object.defineProperty(process, 'platform', { | ||
value: platform, | ||
writable: false | ||
}); | ||
|
||
path.sep = '\\'; | ||
path.resolve = path[platform].resolve; | ||
path.join = path.win32.join; | ||
path.normalize = path.win32.normalize; | ||
|
||
return fn(restore); | ||
} catch(e) { | ||
restore(); | ||
throw e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
var WinPath = require('../common').WinPath; | ||
var test = require('tap').test | ||
|
||
test("UNIT: WinPath – basic path", function(t) { | ||
var path = new WinPath('basic-path') | ||
|
||
t.same(path.device, ''); | ||
t.same(path.sep, ''); | ||
t.same(path.tail, 'basic-path') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – relative path", function(t) { | ||
var path = new WinPath('relative\\path') | ||
|
||
t.same(path.device, ''); | ||
t.same(path.sep, ''); | ||
t.same(path.tail, 'relative\\path') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – relative path \w glob", function(t) { | ||
var path = new WinPath('relative\\path\\*') | ||
|
||
t.same(path.device, ''); | ||
t.same(path.sep, ''); | ||
t.same(path.tail, 'relative\\path\\*') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – absolute path", function(t) { | ||
var path = new WinPath('\\relative\\path') | ||
|
||
t.same(path.device, ''); | ||
t.same(path.sep, '\\'); | ||
t.same(path.tail, 'relative\\path') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – absolute path \w glob", function(t) { | ||
var path = new WinPath('\\relative\\path\\*') | ||
|
||
t.same(path.device, ''); | ||
t.same(path.sep, '\\'); | ||
t.same(path.tail, 'relative\\path\\*') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – UNC path", function(t) { | ||
var path = new WinPath('\\\\vmware-share\\share-name\\relative\\path') | ||
|
||
t.same(path.device, '\\\\vmware-share\\share-name'); | ||
t.same(path.sep, '\\'); | ||
t.same(path.tail, 'relative\\path') | ||
|
||
t.end(); | ||
}); | ||
|
||
test("UNIT: WinPath – UNC path \w glob", function(t) { | ||
var path = new WinPath('\\\\vmware-share\\share-name\\relative\\path\\*') | ||
|
||
t.same(path.device, '\\\\vmware-share\\share-name'); | ||
t.same(path.sep, '\\'); | ||
t.same(path.tail, 'relative\\path\\*') | ||
|
||
t.end(); | ||
}); |