Fix IsHiddenPath treating current directory as hidden (closes #14)
IsHiddenPath(".") incorrectly returned true because path.Clean(".")
starts with a dot. Add explicit check for "." before the HasPrefix
check. Add test cases for ".", "./", and "./file.txt".
This commit is contained in:
parent
1f12d10cb7
commit
377fdfb503
@ -385,6 +385,9 @@ func (s *Scanner) ToManifest(ctx context.Context, w io.Writer, progress chan<- S
|
|||||||
// The path should use forward slashes.
|
// The path should use forward slashes.
|
||||||
func IsHiddenPath(p string) bool {
|
func IsHiddenPath(p string) bool {
|
||||||
tp := path.Clean(p)
|
tp := path.Clean(p)
|
||||||
|
if tp == "." {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if strings.HasPrefix(tp, ".") {
|
if strings.HasPrefix(tp, ".") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -352,6 +352,9 @@ func TestIsHiddenPath(t *testing.T) {
|
|||||||
{"/absolute/.hidden", true},
|
{"/absolute/.hidden", true},
|
||||||
{"./relative", false}, // path.Clean removes leading ./
|
{"./relative", false}, // path.Clean removes leading ./
|
||||||
{"a/b/c/.d/e", true},
|
{"a/b/c/.d/e", true},
|
||||||
|
{".", false}, // current directory is not hidden (#14)
|
||||||
|
{"./", false}, // current directory with trailing slash
|
||||||
|
{"./file.txt", false}, // file in current directory
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user