Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path separator matching in filecount input #6077

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions internal/globpath/globpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func Compile(path string) (*GlobPath, error) {
out := GlobPath{
hasMeta: hasMeta(path),
HasSuperMeta: hasSuperMeta(path),
path: path,
path: filepath.FromSlash(path),
}

// if there are no glob meta characters in the path, don't bother compiling
Expand All @@ -41,8 +41,9 @@ func Compile(path string) (*GlobPath, error) {
return &out, nil
}

// Match returns all files matching the expression
// If it's a static path, returns path
// Match returns all files matching the expression.
// If it's a static path, returns path.
// All returned path will have the host platform separator.
func (g *GlobPath) Match() []string {
if !g.hasMeta {
return []string{g.path}
Expand Down Expand Up @@ -82,7 +83,8 @@ func (g *GlobPath) Match() []string {
return out
}

// MatchString test a string against the glob
// MatchString tests the path string against the glob. The path should contain
// the host platform separator.
func (g *GlobPath) MatchString(path string) bool {
if !g.HasSuperMeta {
res, _ := filepath.Match(g.path, path)
Expand All @@ -96,6 +98,7 @@ func (g *GlobPath) MatchString(path string) bool {
// - any directory under these roots may contain a matching file
// - no file outside of these roots can match the pattern
// Note that it returns both files and directories.
// All returned path will have the host platform separator.
func (g *GlobPath) GetRoots() []string {
if !g.hasMeta {
return []string{g.path}
Expand Down
11 changes: 11 additions & 0 deletions internal/globpath/globpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,14 @@ func TestMatch_ErrPermission(t *testing.T) {
require.Equal(t, test.expected, actual)
}
}

func TestWindowsSeparator(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Skipping Windows only test")
}

glob, err := Compile("testdata/nested1")
require.NoError(t, err)
ok := glob.MatchString("testdata\\nested1")
require.True(t, ok)
}