@@ -397,16 +397,33 @@ const isDots = (p: string) => p === '.' || p === '..'
397397const isDrive = ( p : ParseReturn | undefined ) =>
398398 typeof p === 'string' && / ^ [ a - z ] : $ / i. test ( p )
399399
400- // a row or split path that starts with a Windows UNC root, like
401- // `//host/share`, with a string host and share. `//?/...` is not one.
402- const isUNC = ( p : ParseReturn [ ] ) =>
403- p [ 0 ] === '' &&
404- p [ 1 ] === '' &&
405- typeof p [ 2 ] === 'string' &&
406- p [ 2 ] !== '' &&
407- p [ 2 ] !== '?' &&
408- typeof p [ 3 ] === 'string' &&
409- p [ 3 ] !== ''
400+ // true for the `UNC` portion of a long UNC root, //?/UNC/host/share
401+ const isLongUNC = ( p : ParseReturn | undefined ) =>
402+ typeof p === 'string' && / ^ u n c $ / i. test ( p )
403+
404+ // The index of the host in a row or split path that starts with a
405+ // Windows UNC root: 2 for `//host/share`, and 4 for
406+ // `//?/UNC/host/share`. Otherwise -1. `//?/c:` is not one.
407+ const uncHost = ( p : ParseReturn [ ] ) => {
408+ if ( p [ 0 ] !== '' || p [ 1 ] !== '' ) return - 1
409+ const h =
410+ p [ 2 ] !== '?' ? 2
411+ : isLongUNC ( p [ 3 ] ) ? 4
412+ : - 1
413+ const host = p [ h ]
414+ const share = p [ h + 1 ]
415+ return (
416+ h !== - 1 &&
417+ host !== undefined &&
418+ host !== '' &&
419+ host !== GLOBSTAR &&
420+ share !== undefined &&
421+ share !== '' &&
422+ share !== GLOBSTAR
423+ ) ?
424+ h
425+ : - 1
426+ }
410427
411428// true if ** can walk the path portion: not `.` or `..`, and not a
412429// dotfile unless `dot` is set
@@ -626,13 +643,16 @@ export class Minimatch {
626643
627644 // On Windows, the index of the last root portion of a row, as
628645 // #matchRow finds it: 0 for `c:/...`, 3 for `//?/c:/...` and
629- // `//host/share/...`. Otherwise -1.
646+ // `//host/share/...`, and 5 for `//?/UNC/host/share/...`. Otherwise
647+ // -1.
630648 #rootIndex( row : ParseReturn [ ] ) {
631649 if ( ! this . isWindows ) return - 1
632650 if ( isDrive ( row [ 0 ] ) ) return 0
633651 const uncDrive =
634652 row [ 0 ] === '' && row [ 1 ] === '' && row [ 2 ] === '?' && isDrive ( row [ 3 ] )
635- return uncDrive || isUNC ( row ) ? 3 : - 1
653+ if ( uncDrive ) return 3
654+ const h = uncHost ( row )
655+ return h === - 1 ? - 1 : h + 1
636656 }
637657
638658 hasMagic ( ) : boolean {
@@ -683,17 +703,19 @@ export class Minimatch {
683703 // glob --> Matchers
684704 let set = this . globParts . map ( ( s , _ , __ ) => {
685705 if ( this . isWindows && this . windowsNoMagicRoot ) {
686- // check if it's a drive or unc path.
706+ // check if it's a drive or unc path. The root of a long UNC
707+ // path, //?/UNC/host/share, is 6 portions.
708+ const n = s [ 2 ] === '?' && isLongUNC ( s [ 3 ] ) ? 6 : 4
687709 const isUNC =
688710 s [ 0 ] === '' &&
689711 s [ 1 ] === '' &&
690712 ( s [ 2 ] === '?' || ! globMagic . test ( s [ 2 ] ) ) &&
691- ! globMagic . test ( s [ 3 ] )
713+ s . slice ( 3 , n ) . every ( p => ! globMagic . test ( p ) )
692714 const isDrive = / ^ [ a - z ] : / i. test ( s [ 0 ] )
693715 if ( isUNC ) {
694716 return [
695- ...s . slice ( 0 , 4 ) . map ( p => this . #norm( p ) ) ,
696- ...s . slice ( 4 ) . map ( ss => this . parse ( ss ) ) ,
717+ ...s . slice ( 0 , n ) . map ( p => this . #norm( p ) ) ,
718+ ...s . slice ( n ) . map ( ss => this . parse ( ss ) ) ,
697719 ]
698720 } else if ( isDrive ) {
699721 return [
@@ -718,9 +740,9 @@ export class Minimatch {
718740 p [ 0 ] === '' &&
719741 p [ 1 ] === '' &&
720742 this . globParts [ i ] [ 2 ] === '?' &&
721- typeof p [ 3 ] === 'string' &&
722- / ^ [ a - z ] : $ / i. test ( p [ 3 ] )
743+ ( isDrive ( p [ 3 ] ) || isLongUNC ( this . globParts [ i ] [ 3 ] ) )
723744 ) {
745+ if ( isLongUNC ( this . globParts [ i ] [ 3 ] ) ) p [ 3 ] = 'UNC'
724746 p [ 2 ] = '?'
725747 }
726748 }
@@ -1319,20 +1341,25 @@ export class Minimatch {
13191341 let fileStartIndex = 0
13201342 let patternStartIndex = 0
13211343
1322- // UNC paths like //?/X:/... can match X:/... and vice versa
1344+ // UNC paths like //?/X:/... can match X:/... and vice versa, and
1345+ // //?/UNC/host/share/... can match //host/share/... and vice versa.
13231346 // Drive letters in absolute drive or unc paths, and the host and
1324- // share of UNC paths like //host/share/..., are always compared
1325- // case-insensitively.
1326- // Level 2 can resolve the share away (//h/s/../x), so the UNC root
1327- // is found in the resolved parts.
1328- if ( this . isWindows && isUNC ( resolved ) && isUNC ( pattern ) ) {
1329- const [ , , fh , fs ] = resolved
1330- const [ , , ph , ps ] = pattern as string [ ]
1331- if (
1332- fh ! . toLowerCase ( ) === ph ! . toLowerCase ( ) &&
1333- fs ! . toLowerCase ( ) === ps ! . toLowerCase ( )
1347+ // share of UNC paths, are always compared case-insensitively.
1348+ const fh = this . isWindows ? uncHost ( resolved ) : - 1
1349+ const ph = fh === - 1 ? - 1 : uncHost ( pattern )
1350+ if ( ph !== - 1 ) {
1351+ const host = pattern [ ph ]
1352+ const share = pattern [ ph + 1 ]
1353+ if ( typeof host !== 'string' || typeof share !== 'string' ) {
1354+ // a host or share with magic is matched as usual
1355+ fileStartIndex = fh
1356+ patternStartIndex = ph
1357+ } else if (
1358+ resolved [ fh ] ! . toLowerCase ( ) === host . toLowerCase ( ) &&
1359+ resolved [ fh + 1 ] ! . toLowerCase ( ) === share . toLowerCase ( )
13341360 ) {
1335- patternStartIndex = fileStartIndex = 4
1361+ fileStartIndex = fh + 2
1362+ patternStartIndex = ph + 2
13361363 }
13371364 } else if ( this . isWindows ) {
13381365 const fileDrive =
0 commit comments