Skip to content

Commit

Permalink
add windowsPathsNoEscape option
Browse files Browse the repository at this point in the history
Fix: #468
  • Loading branch information
isaacs committed May 12, 2022
1 parent d13cb06 commit ad12334
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function setopts (self, pattern, options) {
pattern = "**/" + pattern
}

self.windowsPathsNoEscape = !!options.windowsPathsNoEscape
if (self.windowsPathsNoEscape) {
pattern = pattern.replace(/\\/g, '/')
}

self.silent = !!options.silent
self.pattern = pattern
self.strict = options.strict !== false
Expand Down
34 changes: 34 additions & 0 deletions test/windows-paths-no-escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 nowinpath = new g.Glob(pattern, {
windowsPathsNoEscape: false,
noprocess: true,
})
t.strictSame([def.pattern, winpath.pattern, nowinpath.pattern], [
'/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)

0 comments on commit ad12334

Please sign in to comment.