Skip to content

Commit

Permalink
Merge pull request #28 from idoru/fix-abs-windows-path-without-volume
Browse files Browse the repository at this point in the history
Fix abs windows path without volume
  • Loading branch information
bmatcuk authored Dec 17, 2019
2 parents 8fcc087 + ac358a8 commit 50be492
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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
8 changes: 6 additions & 2 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func testPathMatchWith(t *testing.T, idx int, tt MatchTest) {
t.Errorf("#%v. Match(%#q, %#q) = %v, %v want %v, %v", idx, pattern, testPath, ok, err, tt.shouldMatch, tt.expectedErr)
}

if isStandardPattern(pattern) {
if isStandardPattern(tt.pattern) {
stdOk, stdErr := filepath.Match(pattern, testPath)
if ok != stdOk || !compareErrors(err, stdErr) {
t.Errorf("#%v. PathMatch(%#q, %#q) != filepath.Match(...). Got %v, %v want %v, %v", idx, pattern, testPath, ok, err, stdOk, stdErr)
Expand All @@ -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 All @@ -226,7 +230,7 @@ func testGlobWith(t *testing.T, idx int, tt MatchTest, basepath string) {
t.Errorf("#%v. Glob(%#q) has error %v, but should be %v", idx, pattern, err, tt.expectedErr)
}

if isStandardPattern(pattern) {
if isStandardPattern(tt.pattern) {
stdMatches, stdErr := filepath.Glob(pattern)
if !compareSlices(matches, stdMatches) || !compareErrors(err, stdErr) {
t.Errorf("#%v. Glob(%#q) != filepath.Glob(...). Got %#v, %v want %#v, %v", idx, pattern, matches, err, stdMatches, stdErr)
Expand Down

0 comments on commit 50be492

Please sign in to comment.