Skip to content

Commit

Permalink
Do not use filepath.Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Jul 5, 2024
1 parent fe9dc4c commit 9b30ec5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ func isSymlinkToDir(path string, de os.DirEntry) bool {
return false
}

func trimPath(path string) string {
if len(path) == 0 {
return "."
}

bytes := stringBytes(path)

for len(bytes) > 1 && bytes[0] == '.' && (bytes[1] == '/' || bytes[1] == '\\') {
bytes = bytes[2:]
}

return byteString(bytes)
}

func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool {
r.killed = false
conf := fastwalk.Config{
Expand All @@ -244,7 +258,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
if err != nil {
return nil
}
path = filepath.Clean(path)
path = trimPath(path)
if path != "." {
isDir := de.IsDir()
if isDir || opts.follow && isSymlinkToDir(path, de) {
Expand Down

0 comments on commit 9b30ec5

Please sign in to comment.