diff --git a/lib/osutil/glob_windows.go b/lib/osutil/glob_windows.go index 5952f18a5..e521330c0 100644 --- a/lib/osutil/glob_windows.go +++ b/lib/osutil/glob_windows.go @@ -26,7 +26,7 @@ func Glob(pattern string) (matches []string, err error) { return []string{pattern}, nil } - dir, file := filepath.Split(pattern) + dir, file := filepath.Split(filepath.Clean(pattern)) switch dir { case "": dir = "." diff --git a/lib/osutil/glob_windows_test.go b/lib/osutil/glob_windows_test.go new file mode 100644 index 000000000..9d552bfd5 --- /dev/null +++ b/lib/osutil/glob_windows_test.go @@ -0,0 +1,29 @@ +// Copyright (C) 2014 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at http://mozilla.org/MPL/2.0/. + +// +build windows + +package osutil_test + +import ( + "testing" + + "github.com/syncthing/syncthing/lib/osutil" +) + +func TestGlob(t *testing.T) { + testcases := []string{ + `C:\*`, + `\\?\C:\*`, + `\\?\C:\Users`, + `\\?\\\?\C:\Users`, + } + for _, tc := range testcases { + if _, err := osutil.Glob(tc); err != nil { + t.Fatalf("pattern %s failed: %v", tc, err) + } + } +}