Skip to content

Commit de623e8

Browse files
committed
made filepath sanitization optional
1 parent 42066e0 commit de623e8

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

fileupload.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func getValidFileNameWithDupIndex(path string, filename string, duplicateIndex i
8080

8181
// path doesn't exist so we can return this path
8282
if _, err := os.Stat(fullpath); os.IsNotExist(err) {
83-
return strings.ToUpper(dupStr + filename)
83+
return strings.ToLower(dupStr + filename)
8484
}
8585

8686
//otherwise increase file index and
@@ -378,15 +378,16 @@ func ProcessImageWithEndpoint(endpoint string, ext string, imgData io.Reader, op
378378
if err != nil {
379379
return nil, fmt.Errorf("statuscode %v", err)
380380
}
381-
if res.StatusCode != 200 {
382-
return nil, fmt.Errorf("failed with status code: %d", res.StatusCode)
383-
}
384381
defer res.Body.Close()
385382

386383
b, err = ioutil.ReadAll(res.Body)
387384
if err != nil {
388385
return nil, fmt.Errorf("failed reading final bytes %v", err)
389386
}
387+
388+
if res.StatusCode != 200 {
389+
return nil, fmt.Errorf("failed with status code: %d and message %s", res.StatusCode, string(b))
390+
}
390391
return b, nil
391392
}
392393

@@ -422,7 +423,6 @@ func (fs *LocalFileStorage) OpenFile(filename string) (b []byte, fileName string
422423
}
423424

424425
func (fs *LocalFileStorage) SaveFile(filename string, r io.Reader) (fileName string, url string, err error) {
425-
filename = getValidFileName(fs.AttachmentsFolder, filename)
426426
f, err := os.OpenFile(fs.AttachmentsFolder+filename, os.O_RDWR|os.O_CREATE, 0666)
427427
if err != nil {
428428
return "", "", fmt.Errorf("Failed to create a file on the filesystem: %v", err)

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ replace bitbucket.org/iqhive/tkt-shared => ../tkt-shared
66

77
require (
88
github.com/kennygrant/sanitize v1.2.4
9-
github.com/manhtai/gopngquant v0.0.0-20180310144719-578cebc80102
10-
github.com/manhtai/imagequant v0.0.0-20180310104925-a76d35dcb570 // indirect
119
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
1210
)

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
22
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
3-
github.com/manhtai/gopngquant v0.0.0-20180310144719-578cebc80102 h1:bShgP1wiKAQf05xCYAVZJ0ghMq6vnBy+ioKGPip1gEI=
4-
github.com/manhtai/gopngquant v0.0.0-20180310144719-578cebc80102/go.mod h1:jHu+AhKQgxLdKw7pisWUAD+BeH38FhmHDTtDBsXG1sA=
5-
github.com/manhtai/imagequant v0.0.0-20180310104925-a76d35dcb570 h1:RJ95GXJWSewO5Mhi+jD4sX6b5RUk3S3/OiDO0+BBxCI=
6-
github.com/manhtai/imagequant v0.0.0-20180310104925-a76d35dcb570/go.mod h1:LTQQU89K3IGCYY8a1nqBJVT1rH29s4nBygn/653/HBk=
73
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
84
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
95
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=

0 commit comments

Comments
 (0)