Skip to content

Commit 61cc5a2

Browse files
committed
join string pattern sections properly
Fix: #547
1 parent 46ff653 commit 61cc5a2

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

benchmark.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ t () {
4141
# warm up the fs cache so we don't get a spurious slow first result
4242
bash -c 'for i in **; do :; done'
4343

44+
cd "$wd/bench-working-dir/fixture"
4445

4546
for p in "${patterns[@]}"; do
4647
echo

patterns.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
patterns=(
2+
'{0000,0,1111,1}/{0000,0,1111,1}/{0000,0,1111,1}/**'
3+
24
'**'
35
'**/..'
46

src/bin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { foregroundChild } from 'foreground-child'
33
import { existsSync } from 'fs'
44
import { jack } from 'jackspeak'
5+
import { join } from 'path'
56
import { version } from '../package.json'
67
import { globStream } from './index.js'
78

@@ -234,7 +235,9 @@ try {
234235
const patterns = values.all
235236
? positionals
236237
: positionals.filter(p => !existsSync(p))
237-
const matches = values.all ? [] : positionals.filter(p => existsSync(p))
238+
const matches = values.all
239+
? []
240+
: positionals.filter(p => existsSync(p)).map(p => join(p))
238241
const stream = globStream(patterns, {
239242
absolute: values.absolute,
240243
cwd: values.cwd,

src/processor.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ export class Processor {
146146
(rest = pattern.rest())
147147
) {
148148
const c = t.resolve(p)
149-
// we can be reasonably sure that .. is a readable dir
150-
if (c.isUnknown() && p !== '..') break
151149
t = c
152150
pattern = rest
153151
changed = true
@@ -163,13 +161,10 @@ export class Processor {
163161
// more strings for an unknown entry,
164162
// or a pattern starting with magic, mounted on t.
165163
if (typeof p === 'string') {
166-
// must be final entry
167-
if (!rest) {
168-
const ifDir = p === '..' || p === '' || p === '.'
169-
this.matches.add(t.resolve(p), absolute, ifDir)
170-
} else {
171-
this.subwalks.add(t, pattern)
172-
}
164+
// must not be final entry, otherwise we would have
165+
// concatenated it earlier.
166+
const ifDir = p === '..' || p === '' || p === '.'
167+
this.matches.add(t.resolve(p), absolute, ifDir)
173168
continue
174169
} else if (p === GLOBSTAR) {
175170
// if no rest, match and subwalk pattern

test/bin.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn, SpawnOptions } from 'child_process'
2-
import t from 'tap'
32
import { sep } from 'path'
3+
import t from 'tap'
44
import { version } from '../package.json'
55
const bin = require.resolve('../dist/cjs/src/bin.js')
66

@@ -66,8 +66,14 @@ t.test('finds matches for a pattern', async t => {
6666

6767
const c = `node -p "process.argv.map(s=>s.toUpperCase())"`
6868
const cmd = await run(['**/*.y', '-c', c], { cwd })
69-
t.match(cmd.stdout, `'a${sep}x.y'`.toUpperCase())
70-
t.match(cmd.stdout, `'a${sep}b${sep}z.y'`.toUpperCase())
69+
t.match(cmd.stdout, `'a${sep.replace(/\\/g, '\\\\')}x.y'`.toUpperCase())
70+
t.match(
71+
cmd.stdout,
72+
`'a${sep.replace(/\\/g, '\\\\')}b${sep.replace(
73+
/\\/g,
74+
'\\\\'
75+
)}z.y'`.toUpperCase()
76+
)
7177
})
7278

7379
t.test('prioritizes exact match if exists, unless --all', async t => {
@@ -76,7 +82,7 @@ t.test('prioritizes exact match if exists, unless --all', async t => {
7682
'[id].tsx': '',
7783
'i.tsx': '',
7884
'd.tsx': '',
79-
}
85+
},
8086
})
8187
const res = await run(['routes/[id].tsx'], { cwd })
8288
t.equal(res.stdout, `routes${sep}[id].tsx\n`)

test/progra-tilde.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://github.com/isaacs/node-glob/issues/547
2+
import t from 'tap'
3+
4+
import { globSync } from '../dist/cjs/src/index.js'
5+
6+
if (process.platform !== 'win32') {
7+
t.pass('no need to test this except on windows')
8+
process.exit(0)
9+
}
10+
11+
const dir = t.testdir({
12+
'program files': {
13+
a: '',
14+
b: '',
15+
c: '',
16+
},
17+
})
18+
19+
t.strictSame(
20+
globSync('progra~1\\*', { cwd: dir, windowsPathsNoEscape: true }).sort(
21+
(a, b) => a.localeCompare(b, 'en')
22+
),
23+
['a', 'b', 'c']
24+
)

0 commit comments

Comments
 (0)