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: v9.0.0
Choose a base ref
...
head repository: isaacs/minimatch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.0.1
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 20, 2023

  1. Copy the full SHA
    383ba5a View commit details
  2. 9.0.1

    isaacs committed May 20, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f1b11e7 View commit details
Showing with 26 additions and 23 deletions.
  1. +2 −2 package-lock.json
  2. +1 −1 package.json
  3. +19 −20 src/index.ts
  4. +4 −0 test/unc.ts
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": "9.0.0",
"version": "9.0.1",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/minimatch.git"
39 changes: 19 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -757,40 +757,39 @@ export class Minimatch {
matchOne(file: string[], pattern: ParseReturn[], partial: boolean = false) {
const options = this.options

// a UNC pattern like //?/c:/* can match a path like c:/x
// and vice versa
// UNC paths like //?/X:/... can match X:/... and vice versa
// Drive letters in absolute drive or unc paths are always compared
// case-insensitively.
if (this.isWindows) {
const fileDrive = typeof file[0] === 'string' && /^[a-z]:$/i.test(file[0])
const fileUNC =
!fileDrive &&
file[0] === '' &&
file[1] === '' &&
file[2] === '?' &&
typeof file[3] === 'string' &&
/^[a-z]:$/i.test(file[3])

const patternDrive =
typeof pattern[0] === 'string' && /^[a-z]:$/i.test(pattern[0])
const patternUNC =
!patternDrive &&
pattern[0] === '' &&
pattern[1] === '' &&
pattern[2] === '?' &&
typeof pattern[3] === 'string' &&
/^[a-z]:$/i.test(pattern[3])

if (fileUNC && patternUNC) {
const fd = file[3] as string
const pd = pattern[3] as string
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined
if (typeof fdi === 'number' && typeof pdi === 'number') {
const [fd, pd]: [string, string] = [file[fdi], pattern[pdi] as string]
if (fd.toLowerCase() === pd.toLowerCase()) {
file[3] = pd
}
} else if (patternUNC && typeof file[0] === 'string') {
const pd = pattern[3] as string
const fd = file[0]
if (pd.toLowerCase() === fd.toLowerCase()) {
pattern[3] = fd
pattern = pattern.slice(3)
}
} else if (fileUNC && typeof pattern[0] === 'string') {
const fd = file[3]
if (fd.toLowerCase() === pattern[0].toLowerCase()) {
pattern[0] = fd
file = file.slice(3)
pattern[pdi] = fd
if (pdi > fdi) {
pattern = pattern.slice( pdi)
} else if (fdi > pdi) {
file = file.slice(fdi)
}
}
}
}
4 changes: 4 additions & 0 deletions test/unc.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ const cases: Case[] = [
['c:/x', '//?/C:/*', true],
['//?/c:/x', 'C:/*', true],
['//?/c:/x', '//?/C:/*', true],
['c:/x', '//?/C:/*', true],
['c:/x', 'C:/*', true],
['C:/x', '//?/c:/*', true],
['C:/x', 'c:/*', true],

['d:/x', '//?/c:/*', false],
['//?/d:/x', 'c:/*', false],