Skip to content

Commit

Permalink
fix path check
Browse files Browse the repository at this point in the history
Signed-off-by: nikpivkin <[email protected]>
  • Loading branch information
nikpivkin committed Sep 25, 2024
1 parent 60e553c commit a002320
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/mapfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ func cleanPath(path string) string {
}

func (m *FS) isPathAboveRoot(name string) bool {
return strings.HasPrefix(name, "..") && m.underlyingRoot != ""
return (name == ".." || strings.HasPrefix(name, "../")) && m.underlyingRoot != ""
}
7 changes: 6 additions & 1 deletion pkg/mapfs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ func TestFS_RemoveAll(t *testing.T) {
func TestFS_WithUnderlyingRoot(t *testing.T) {
root := "testdata/subdir"
fsys := mapfs.New(mapfs.WithUnderlyingRoot(root))
fsys.WriteFile("foo.txt", root+"/foo.txt")
require.NoError(t, fsys.WriteFile("foo.txt", root+"/foo.txt"))
require.NoError(t, fsys.WriteFile("..foo.txt", root+"/..foo.txt"))

fi, err := fsys.Stat("..")
require.NoError(t, err)
Expand All @@ -495,4 +496,8 @@ func TestFS_WithUnderlyingRoot(t *testing.T) {
fi, err = fsys.Stat("foo.txt")
require.NoError(t, err)
assert.False(t, fi.IsDir())

fi, err = fsys.Stat("..foo.txt")
require.NoError(t, err)
assert.False(t, fi.IsDir())
}
Empty file.

0 comments on commit a002320

Please sign in to comment.