On Windows, FilepathGlob can return file paths that are not valid UNC paths, even when the input pattern is a normal UNC glob such as \\server\share\logs\*.log. The leading \ that identifies a UNC volume is effectively reduced to a single , so callers treat the path as drive-relative (e.g. C:\server\share\logs\*.log). We're using version 4.10.0 of doublestar.
Breaking down exactly what happens in FilepathGlob that causes this:
-
filepath.Clean / filepath.ToSlash: Normalizes the pattern; on Windows a UNC glob becomes a slash form whose directory prefix starts with //server/share/....
-
SplitPattern: Splits that string into a base (still with the UNC-style) and the glob fragment passed to Glob.
-
Glob on os.DirFS(base): Walks the tree and returns relative match paths (names under base).
-
path.Join(base, matches[i]): Recombines each hit with base. path.Join applies path.Clean, which collapses the leading // (UNC in slash form) to a single /.
-
filepath.FromSlash(...): after step 4 the path no longer has a proper \-UNC root, so you get one leading \ instead of \, and callers treat it as drive-relative (e.g. \server\share... → C:\server\share...).
I could also reproduce step 4 with this test:
func TestDoublestarUtils_FilepathGlobPreservesUNC(t *testing.T) {
const uncGlobPattern = `\\server\share\logs\*.log`
base := "//server/share/logs"
matches := []string{"app.log"}
for i := range matches {
matches[i] = filepath.FromSlash(path.Join(base, matches[i]))
}
wantSlashNormalizedUNC := "//server/share/logs/app.log"
gotSlash := filepath.ToSlash(matches[0])
if gotSlash != wantSlashNormalizedUNC {
t.Fatalf("%s: expected %q but got %q", uncGlobPattern, wantSlashNormalizedUNC, gotSlash)
}
}
Is this intended behavior? Or a bug? I couldn't find any related issues or documentation about this, happy to discuss as well
On Windows, FilepathGlob can return file paths that are not valid UNC paths, even when the input pattern is a normal UNC glob such as
\\server\share\logs\*.log. The leading \ that identifies a UNC volume is effectively reduced to a single , so callers treat the path as drive-relative (e.g.C:\server\share\logs\*.log). We're using version4.10.0of doublestar.Breaking down exactly what happens in FilepathGlob that causes this:
filepath.Clean / filepath.ToSlash: Normalizes the pattern; on Windows a UNC glob becomes a slash form whose directory prefix starts with
//server/share/....SplitPattern: Splits that string into a base (still with the UNC-style) and the glob fragment passed to Glob.
Glob on os.DirFS(base): Walks the tree and returns relative match paths (names under base).
path.Join(base, matches[i]): Recombines each hit with base. path.Join applies path.Clean, which collapses the leading // (UNC in slash form) to a single /.
filepath.FromSlash(...): after step 4 the path no longer has a proper \-UNC root, so you get one leading \ instead of \, and callers treat it as drive-relative (e.g. \server\share... → C:\server\share...).
I could also reproduce step 4 with this test:
Is this intended behavior? Or a bug? I couldn't find any related issues or documentation about this, happy to discuss as well