Skip to content

Commit 02b76fd

Browse files
committed
fix nocase matching on case-sensitive filesystems
If the platform indicates that the filesystem is likely case-sensitive (ie, not darwin or win32), and nocase:true is set, we can't know if that's indicating that the filesystem _itself_ is case-insensitive, or if the user simply wants to perform case-insensitive matching. In the case where it is in fact likely case-sensitive, and `nocase:true` is set, do _not_ set `nocaseMagicOnly`, because filesystem operations will not be run case-insensitively. Fix: #526
1 parent 464f441 commit 02b76fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/glob.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,21 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
457457
}
458458
this.nocase = this.scurry.nocase
459459

460+
// If you do nocase:true on a case-sensitive file system, then
461+
// we need to use regexps instead of strings for non-magic
462+
// path portions, because statting `aBc` won't return results
463+
// for the file `AbC` for example.
464+
const nocaseMagicOnly =
465+
this.platform === 'darwin' || this.platform === 'win32'
466+
460467
const mmo: MinimatchOptions = {
461468
// default nocase based on platform
462469
...opts,
463470
dot: this.dot,
464471
matchBase: this.matchBase,
465472
nobrace: this.nobrace,
466473
nocase: this.nocase,
467-
nocaseMagicOnly: true,
474+
nocaseMagicOnly,
468475
nocomment: true,
469476
noext: this.noext,
470477
nonegate: true,

test/nocase-magic-only.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import t from 'tap'
2+
import { Glob } from '../dist/cjs/src/index.js'
3+
4+
const darwin = new Glob('x', { nocase: true, platform: 'darwin' })
5+
const linux = new Glob('x', { nocase: true, platform: 'linux' })
6+
7+
t.type(darwin.patterns[0].pattern(), 'string')
8+
t.type(linux.patterns[0].pattern(), RegExp)

0 commit comments

Comments
 (0)