Skip to content

Commit e940f8b

Browse files
authored
Merge pull request #50 from whickman/wh/handle-bad-file-path
Handle filenames with leading periods correctly
2 parents 053dbd0 + e608ed0 commit e940f8b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

helper/chroot/chroot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func isCrossBoundaries(path string) bool {
3737
path = filepath.ToSlash(path)
3838
path = filepath.Clean(path)
3939

40-
return strings.HasPrefix(path, "..")
40+
return strings.HasPrefix(path, ".."+string(filepath.Separator))
4141
}
4242

4343
func (fs *ChrootHelper) Create(filename string) (billy.File, error) {

helper/chroot/chroot_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ func (s *ChrootSuite) TestCreateErrCrossedBoundary(c *C) {
3737
c.Assert(err, Equals, billy.ErrCrossedBoundary)
3838
}
3939

40+
func (s *ChrootSuite) TestLeadingPeriodsPathNotCrossedBoundary(c *C) {
41+
m := &test.BasicMock{}
42+
43+
fs := New(m, "/foo")
44+
f, err := fs.Create("..foo")
45+
c.Assert(err, IsNil)
46+
c.Assert(f.Name(), Equals, "..foo")
47+
}
48+
4049
func (s *ChrootSuite) TestOpen(c *C) {
4150
m := &test.BasicMock{}
4251

0 commit comments

Comments
 (0)