From 383ba5adb18d74666e05906a5044b5f7678a15b2 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 20 May 2023 13:53:29 -0700 Subject: [PATCH 1/2] windows: Compare drive letters case-insensitively when not UNC Fix: https://github.com/isaacs/node-glob/issues/527 --- src/index.ts | 39 +++++++++++++++++++-------------------- test/unc.ts | 4 ++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index a8e55a03..9d5c4571 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) + } } } } diff --git a/test/unc.ts b/test/unc.ts index 912a5abd..ca36e379 100644 --- a/test/unc.ts +++ b/test/unc.ts @@ -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], From f1b11e7906818f0ae455a82fe7c1bfcf655c786d Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 20 May 2023 13:53:42 -0700 Subject: [PATCH 2/2] 9.0.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d72170ee..be4388e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "minimatch", - "version": "9.0.0", + "version": "9.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "minimatch", - "version": "9.0.0", + "version": "9.0.1", "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" diff --git a/package.json b/package.json index 06d796a2..d5ee74e3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (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"