diff --git a/utils.go b/utils.go index 0944e4f..57d378d 100644 --- a/utils.go +++ b/utils.go @@ -40,7 +40,9 @@ func IsConfiguration(path string) bool { // IsDotFile returns whether or not path has dot as a prefix. func IsDotFile(path string) bool { - return strings.HasPrefix(filepath.Base(path), ".") + path = filepath.Clean(path) + base := filepath.Base(path) + return strings.HasPrefix(base, ".") && base != "." && base != ".." } // IsVendor returns whether or not path is a vendor path. diff --git a/utils_test.go b/utils_test.go index 267d617..6473f1c 100644 --- a/utils_test.go +++ b/utils_test.go @@ -82,6 +82,22 @@ func (s *EnryTestSuite) TestIsBinary() { } } +func (s *EnryTestSuite) TestIsDotFile() { + tests := []struct { + name string + path string + expected bool + }{ + {name: "TestIsDotFile_1", path: "foo/bar/./", expected: false}, + {name: "TestIsDotFile_2", path: "./", expected: false}, + } + + for _, test := range tests { + is := IsDotFile(test.path) + assert.Equal(s.T(), test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) + } +} + func TestFileCountListSort(t *testing.T) { sampleData := FileCountList{{"a", 8}, {"b", 65}, {"c", 20}, {"d", 90}} const ascending = "ASC"