Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: isaacs/minimatch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.1.1
Choose a base ref
...
head repository: isaacs/minimatch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.2
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Feb 24, 2023

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    isaacs isaacs
    Copy the full SHA
    58917fe View commit details
  2. 7.1.2

    isaacs committed Feb 24, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    isaacs isaacs
    Copy the full SHA
    36c50b7 View commit details
Showing with 31 additions and 15 deletions.
  1. +8 −0 README.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +17 −9 src/index.ts
  5. +3 −3 test/unc.ts
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -320,6 +320,14 @@ is equivalent in all cases).
string is first processed with
`minimatch.levelTwoFileOptimize()` or similar.

### platform

When set to `win32`, this will trigger all windows-specific
behaviors (special handling for UNC paths, and treating `\` as
separators in file paths for comparison.)

Defaults to the value of `process.platform`.

## Comparisons to other fnmatch/glob implementations

While strict compliance with the existing standards is a
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
"name": "minimatch",
"description": "a glob matcher in javascript",
"version": "7.1.1",
"version": "7.1.2",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/minimatch.git"
26 changes: 17 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ export interface MinimatchOptions {
flipNegate?: boolean
preserveMultipleSlashes?: boolean
optimizationLevel?: number
platform?: typeof process.platform
}

export const minimatch = (
@@ -87,19 +88,21 @@ const qmarksTestNoExtDot = ([$0]: RegExpMatchArray) => {
return (f: string) => f.length === len && f !== '.' && f !== '..'
}

type Platform = typeof process.platform
/* c8 ignore start */
const platform =
const defaultPlatform: Platform = (
typeof process === 'object' && process
? (typeof process.env === 'object' &&
process.env &&
process.env.__MINIMATCH_TESTING_PLATFORM__) ||
process.platform
: 'posix'
const isWindows = platform === 'win32'
const path = isWindows ? { sep: '\\' } : { sep: '/' }
) as Platform
type Sep = '\\' | '/'
const path:{[k:string]:{sep:Sep}} = { win32: { sep: '\\' }, posix: { sep: '/' } }
/* c8 ignore stop */

export const sep = path.sep
export const sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep
minimatch.sep = sep

export const GLOBSTAR = Symbol('globstar **')
@@ -306,13 +309,18 @@ export class Minimatch {
globSet: string[]
globParts: string[][]

isWindows: boolean
platform: typeof process.platform

regexp: false | null | MMRegExp
constructor(pattern: string, options: MinimatchOptions = {}) {
assertValidPattern(pattern)

options = options || {}
this.options = options
this.pattern = pattern
this.platform = options.platform || defaultPlatform
this.isWindows = this.platform === 'win32'
this.windowsPathsNoEscape =
!!options.windowsPathsNoEscape || options.allowWindowsEscape === false
if (this.windowsPathsNoEscape) {
@@ -387,7 +395,7 @@ export class Minimatch {
) as ParseReturnFiltered[][]

// do not treat the ? in UNC paths as magic
if (isWindows) {
if (this.isWindows) {
for (let i = 0; i < this.set.length; i++) {
const p = this.set[i]
if (
@@ -710,7 +718,7 @@ export class Minimatch {

// a UNC pattern like //?/c:/* can match a path like c:/x
// and vice versa
if (isWindows) {
if (this.isWindows) {
const fileUNC =
file[0] === '' &&
file[1] === '' &&
@@ -1452,7 +1460,7 @@ export class Minimatch {
// preserveMultipleSlashes is set to true.
if (this.preserveMultipleSlashes) {
return p.split('/')
} else if (isWindows && /^\/\/[^\/]+/.test(p)) {
} else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
// add an extra '' for the one we lose
return ['', ...p.split(/\/+/)]
} else {
@@ -1478,8 +1486,8 @@ export class Minimatch {
const options = this.options

// windows: need to use /, not \
if (path.sep !== '/') {
f = f.split(path.sep).join('/')
if (this.isWindows) {
f = f.split('\\').join('/')
}

// treat the test path as a set of pathparts.
6 changes: 3 additions & 3 deletions test/unc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
process.env.__MINIMATCH_TESTING_PLATFORM__ = 'win32'
import t from 'tap'
import { minimatch, Minimatch, MinimatchOptions } from '../'

t.test('UNC patterns do not lose their //', async t => {
const share = new Minimatch('//host/share/*')
const share = new Minimatch('//host/share/*', { platform: 'win32' })
t.match(share.set, [['', '', 'host', 'share', RegExp]])
const uncPath = new Minimatch('//?/d:/*')
const uncPath = new Minimatch('//?/d:/*', { platform: 'win32' })
t.match(uncPath.set, [['', '', '?', 'd:', RegExp]])
})

@@ -34,6 +33,7 @@ const cases: Case[] = [

t.test('UNC drive letter paths match normal paths', async t => {
for (const [file, pattern, expect, opt = {}] of cases) {
opt.platform = 'win32'
t.test(`f=${file} p=${pattern}`, t => {
t.test('/ only', t => {
t.equal(minimatch(file, pattern, opt), expect)