Skip to content

Commit

Permalink
fix nocase matching on case-sensitive filesystems
Browse files Browse the repository at this point in the history
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
  • Loading branch information
isaacs committed May 9, 2023
1 parent 464f441 commit 02b76fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,21 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
}
this.nocase = this.scurry.nocase

// If you do nocase:true on a case-sensitive file system, then
// we need to use regexps instead of strings for non-magic
// path portions, because statting `aBc` won't return results
// for the file `AbC` for example.
const nocaseMagicOnly =
this.platform === 'darwin' || this.platform === 'win32'

const mmo: MinimatchOptions = {
// default nocase based on platform
...opts,
dot: this.dot,
matchBase: this.matchBase,
nobrace: this.nobrace,
nocase: this.nocase,
nocaseMagicOnly: true,
nocaseMagicOnly,
nocomment: true,
noext: this.noext,
nonegate: true,
Expand Down
8 changes: 8 additions & 0 deletions test/nocase-magic-only.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import t from 'tap'
import { Glob } from '../dist/cjs/src/index.js'

const darwin = new Glob('x', { nocase: true, platform: 'darwin' })
const linux = new Glob('x', { nocase: true, platform: 'linux' })

t.type(darwin.patterns[0].pattern(), 'string')
t.type(linux.patterns[0].pattern(), RegExp)

0 comments on commit 02b76fd

Please sign in to comment.