Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Improve test cases for file resolution #233

Merged
merged 4 commits into from
Aug 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions v2/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,27 @@ func Test_Box_HasDir(t *testing.T) {
func Test_Box_Traversal_Standard(t *testing.T) {
r := require.New(t)
box := New("Test_Box_Traversal_Standard", "")
_, err := box.FindString("../go.mod")
_, err := box.FindString("../fixtures/hello.txt")
r.Error(err)
}

func Test_Box_Traversal_Standard_Depth2(t *testing.T) {
r := require.New(t)
box := New("Test_Box_Traversal_Standard_Depth2", "")
_, err := box.FindString("../../packr/go.mod")
_, err := box.FindString("../../packr/fixtures/hello.txt")
r.Error(err)
}

func Test_Box_Traversal_Backslash(t *testing.T) {
r := require.New(t)
box := New("Test_Box_Traversal_Backslash", "")
_, err := box.FindString("..\\go.mod")
_, err := box.FindString("..\\fixtures\\hello.txt")
r.Error(err)
}

func Test_Box_Traversal_Backslash_Depth2(t *testing.T) {
r := require.New(t)
box := New("Test_Box_Traversal_Backslash_Depth2", "")
_, err := box.FindString("..\\..packr2\\go.mod")
_, err := box.FindString("..\\..\\packr2\\fixtures\\hello.txt")
r.Error(err)
}
4 changes: 2 additions & 2 deletions v2/file/resolver/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (d *Disk) Resolve(box string, name string) (file.File, error) {
return nil, os.ErrNotExist
}

// resolvePathInBase returns a path that is guaranteed to be inside of the base directory or an error
func ResolvePathInBase(base string, path string) (string, error) {
// ResolvePathInBase returns a path that is guaranteed to be inside of the base directory or an error
func ResolvePathInBase(base, path string) (string, error) {
// Determine the absolute file path of the base directory
d, err := filepath.Abs(base)
if err != nil {
Expand Down