-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 8.1 | ||
|
||
- Add `windowsPathsNoEscape` option | ||
|
||
## 8.0 | ||
|
||
- Only support node v12 and higher | ||
|
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,70 @@ | ||
// test that escape chars are handled properly according to configs | ||
// when found in patterns and paths containing glob magic. | ||
|
||
const t = require('tap') | ||
const dir = t.testdir({ | ||
// treat escapes as path separators | ||
a: { | ||
'[x': { | ||
']b': { | ||
y: '', | ||
}, | ||
}, | ||
}, | ||
// escape parent dir name only, not filename | ||
'a[x]b': { | ||
y: '', | ||
}, | ||
// no path separators, all escaped | ||
'a[x]by': '', | ||
}) | ||
|
||
const glob = require('../') | ||
t.test('treat backslash as escape', async t => { | ||
const cases = { | ||
'a[x]b/y': [], | ||
'a\\[x\\]b/y': ['a[x]b/y'], | ||
'a\\[x\\]b\\y': ['a[x]by'], | ||
} | ||
for (const [pattern, expect] of Object.entries(cases)) { | ||
t.test(pattern, t => { | ||
const s = glob.sync(pattern, { cwd: dir }) | ||
.map(s => s.replace(/\\/g, '/')) | ||
t.strictSame(s, expect, 'sync') | ||
glob(pattern, {cwd: dir}, (er, s) => { | ||
if (er) { | ||
throw er | ||
} | ||
s = s.map(s => s.replace(/\\/g, '/')) | ||
t.strictSame(s, expect, 'async') | ||
t.end() | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
t.test('treat backslash as separator', async t => { | ||
Object.defineProperty(process, 'platform', { | ||
value: 'win32' | ||
}) | ||
const cases = { | ||
'a[x]b/y': [], | ||
'a\\[x\\]b/y': ['a/[x/]b/y'], | ||
'a\\[x\\]b\\y': ['a/[x/]b/y'], | ||
} | ||
for (const [pattern, expect] of Object.entries(cases)) { | ||
t.test(pattern, t => { | ||
const s = glob.sync(pattern, { cwd: dir, windowsPathsNoEscape: true }) | ||
.map(s => s.replace(/\\/g, '/')) | ||
t.strictSame(s, expect, 'sync') | ||
glob(pattern, {cwd: dir, windowsPathsNoEscape: true}, (er, s) => { | ||
if (er) { | ||
throw er | ||
} | ||
s = s.map(s => s.replace(/\\/g, '/')) | ||
t.strictSame(s, expect, 'async') | ||
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,45 @@ | ||
const t = require('tap') | ||
const g = require('../') | ||
|
||
const platforms = ['win32', 'posix'] | ||
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform') | ||
for (const p of platforms) { | ||
t.test(p, t => { | ||
Object.defineProperty(process, 'platform', { | ||
value: p, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
}) | ||
t.equal(process.platform, p, 'gut check: actually set platform') | ||
const pattern = '/a/b/c/x\\[a-b\\]y\\*' | ||
const def = new g.Glob(pattern, { noprocess: true }) | ||
const winpath = new g.Glob(pattern, { | ||
windowsPathsNoEscape: true, | ||
noprocess: true, | ||
}) | ||
const winpathLegacy = new g.Glob(pattern, { | ||
allowWindowsEscape: false, | ||
noprocess: true, | ||
}) | ||
const nowinpath = new g.Glob(pattern, { | ||
windowsPathsNoEscape: false, | ||
noprocess: true, | ||
}) | ||
|
||
t.strictSame([ | ||
def.pattern, | ||
nowinpath.pattern, | ||
winpath.pattern, | ||
winpathLegacy.pattern, | ||
], [ | ||
'/a/b/c/x\\[a-b\\]y\\*', | ||
'/a/b/c/x\\[a-b\\]y\\*', | ||
'/a/b/c/x/[a-b/]y/*', | ||
'/a/b/c/x/[a-b/]y/*', | ||
]) | ||
t.end() | ||
}) | ||
} | ||
|
||
Object.defineProperty(process, 'platform', originalPlatform) |