@@ -30,6 +30,86 @@ describe("matching on Windows", () => {
3030 const matches = ( filePath : string , patterns : string [ ] , cwd : string | undefined = WINDOWS_CWD ) =>
3131 matcher ( ) . isFileMatchedByPatterns ( { filePath, cwd, patterns, homeDir : WINDOWS_HOME } )
3232
33+ it . each ( [
34+ "///server/share/docs/**" ,
35+ "////server/share/docs/**" ,
36+ "\\\\\\server\\share\\docs\\**" ,
37+ "\\\\\\\\server\\share\\docs\\**" ,
38+ ] ) ( "treats extra leading separators in a grant as drive-rooted, not UNC: %s" , ( pattern ) => {
39+ expect ( matches ( "//server/share/docs/private.md" , [ pattern ] , "C:/repo" ) ) . toBe ( false )
40+ expect ( matches ( "C:/server/share/docs/private.md" , [ pattern ] , "C:/repo" ) ) . toBe ( true )
41+ expect ( matches ( "//server/share/docs/private.md" , [ "//server/share/docs/**" ] , "C:/repo" ) ) . toBe ( true )
42+ } )
43+
44+ it . each ( [
45+ "///server/share/docs/private.md" ,
46+ "////server/share/docs/private.md" ,
47+ "\\\\\\server\\share\\docs\\private.md" ,
48+ "\\\\\\\\server\\share\\docs\\private.md" ,
49+ ] ) ( "treats extra leading separators in a candidate as drive-rooted, not UNC: %s" , ( filePath ) => {
50+ expect ( matches ( filePath , [ "//server/share/docs/**" ] , "C:/repo" ) ) . toBe ( false )
51+ expect ( matches ( filePath , [ "C:/server/share/docs/**" ] , "C:/repo" ) ) . toBe ( true )
52+ expect ( matches ( filePath , [ "///server/share/docs/**" ] , "C:/repo" ) ) . toBe ( true )
53+ } )
54+
55+ it . each ( [ "//server//share" , "//server///share" , "\\\\server\\\\share" , "\\\\server\\\\\\share" ] ) (
56+ "normalizes repeated separators between a UNC server and share: %s" ,
57+ ( root ) => {
58+ expect ( matches ( "//server/share/docs/private.md" , [ `${ root } /docs/**` ] , "C:/repo" ) ) . toBe ( true )
59+ expect ( matches ( `${ root } /docs/private.md` , [ "//server/share/docs/**" ] , "C:/repo" ) ) . toBe ( true )
60+ expect ( matches ( "//server/share/docs/private.md" , [ "docs/**" ] , root ) ) . toBe ( true )
61+ expect ( matches ( "docs/private.md" , [ "//server/share/docs/**" ] , root ) ) . toBe ( true )
62+ expect ( matches ( "docs/private.md" , [ "C:/server/share/docs/**" ] , root ) ) . toBe ( false )
63+ expect ( matches ( "C:/server/share/docs/private.md" , [ `${ root } /docs/**` ] , "C:/repo" ) ) . toBe ( false )
64+ } ,
65+ )
66+
67+ it . each ( [ "//server" , "\\\\server" ] ) ( "treats an incomplete UNC name as drive-rooted: %s" , ( filePath ) => {
68+ expect ( matches ( filePath , [ "C:/server" ] , "C:/repo" ) ) . toBe ( true )
69+ expect ( matches ( filePath , [ "D:/server" ] , "C:/repo" ) ) . toBe ( false )
70+ expect ( matches ( "C:/server" , [ filePath ] , "C:/repo" ) ) . toBe ( true )
71+ expect ( matches ( "//server/share/docs/private.md" , [ filePath ] , "C:/repo" ) ) . toBe ( false )
72+ } )
73+
74+ it . each ( [
75+ {
76+ cwd : "//server/share/../project" ,
77+ canonicalCwd : "//server/share/project" ,
78+ otherVolume : "//server/project" ,
79+ } ,
80+ {
81+ cwd : "\\\\server\\share\\..\\project" ,
82+ canonicalCwd : "//server/share/project" ,
83+ otherVolume : "//server/project" ,
84+ } ,
85+ { cwd : "C:/../D/project" , canonicalCwd : "C:/D/project" , otherVolume : "D:/project" } ,
86+ { cwd : "C:\\..\\D\\project" , canonicalCwd : "C:/D/project" , otherVolume : "D:/project" } ,
87+ ] ) (
88+ "clamps parent traversal at the volume when normalizing equivalent workspace roots: $cwd" ,
89+ ( { cwd, canonicalCwd, otherVolume } ) => {
90+ const input = {
91+ cwd,
92+ canonicalCwd,
93+ filePath : `${ canonicalCwd } /docs/private.md` ,
94+ }
95+ expect ( matcher ( ) . isFileMatchedByPatterns ( { ...input , patterns : [ `${ otherVolume } /docs/**` ] } ) ) . toBe ( false )
96+ expect ( matcher ( ) . isFileMatchedByPatterns ( { ...input , patterns : [ "docs/**" ] } ) ) . toBe ( true )
97+ expect ( matcher ( ) . isFileMatchedByPatterns ( { ...input , patterns : [ `${ canonicalCwd } /docs/**` ] } ) ) . toBe ( true )
98+ expect (
99+ matcher ( ) . isFileMatchedByPatterns ( {
100+ ...input ,
101+ patterns : [ "docs/**" , `!${ canonicalCwd } /docs/private.md` ] ,
102+ } ) ,
103+ ) . toBe ( false )
104+ expect (
105+ matcher ( ) . isFileMatchedByPatterns ( {
106+ ...input ,
107+ patterns : [ `!${ canonicalCwd } /docs/private.md` , "docs/**" ] ,
108+ } ) ,
109+ ) . toBe ( true )
110+ } ,
111+ )
112+
33113 it . each ( [ undefined , "/ws" , "\\ws" , "//server/share/ws" , "\\\\server\\share\\ws" ] ) (
34114 "preserves cross-volume wildcard exclusions and their order with workspace %s" ,
35115 ( cwd ) => {
0 commit comments