Skip to content

Commit

Permalink
Match absolute patterns without volume on windows
Browse files Browse the repository at this point in the history
In 1.1.5 Glob() on windows matched absolute patterns without volume specified with the current working dir's volume.
This broke in 1.2.x due to the use of filepath.IsAbs() which returns false if the volume is not present.
This was causing paths starting with / or \ on windows to be erroneously evaluated from the current directory.
  • Loading branch information
idoru committed Dec 16, 2019
1 parent 797ac9d commit ac358a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doublestar.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func Glob(pattern string) (matches []string, err error) {
// volumeName will be an empty string. If it is absolute and we're on a
// Windows machine, volumeName will be a drive letter ("C:") for filesystem
// paths or \\<server>\<share> for UNC paths.
isAbs := filepath.IsAbs(pattern)
isAbs := filepath.IsAbs(pattern) || pattern[0] == '\\' || pattern[0] == '/'
volumeName := filepath.VolumeName(pattern)
isWindowsUNC := strings.HasPrefix(volumeName, `\\`)
if isWindowsUNC || isAbs {
Expand Down
4 changes: 4 additions & 0 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func TestGlob(t *testing.T) {
// test both relative paths and absolute paths
testGlobWith(t, idx, tt, "test")
testGlobWith(t, idx, tt, abspath)
volumeName := filepath.VolumeName(abspath)
if volumeName != "" && !strings.HasPrefix(volumeName, `\\`) {
testGlobWith(t, idx, tt, strings.TrimPrefix(abspath, volumeName))
}
}
}
}
Expand Down

0 comments on commit ac358a8

Please sign in to comment.