Skip to content

Commit bd3e9e7

Browse files
committed
Clean path
1 parent ed57927 commit bd3e9e7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

integrations/api_repo_lfs_locks_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
6868
{user: user2, repo: repo1, path: "path/test", httpResult: http.StatusCreated, addTime: []int{0}},
6969
{user: user2, repo: repo1, path: "path/test", httpResult: http.StatusConflict},
7070
{user: user2, repo: repo1, path: "Foo/BaR.zip", httpResult: http.StatusConflict},
71+
{user: user2, repo: repo1, path: "Foo/Test/../subFOlder/../Relative/../BaR.zip", httpResult: http.StatusConflict},
7172
{user: user4, repo: repo1, path: "FoO/BaR.zip", httpResult: http.StatusForbidden},
7273
{user: user4, repo: repo1, path: "path/test-user4", httpResult: http.StatusForbidden},
7374
{user: user2, repo: repo1, path: "patH/Test-user4", httpResult: http.StatusCreated, addTime: []int{0}},

models/lfs_lock.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package models
66

77
import (
88
"fmt"
9+
"path"
910
"strconv"
1011
"strings"
1112
"time"
@@ -26,14 +27,18 @@ type LFSLock struct {
2627
// BeforeInsert is invoked from XORM before inserting an object of this type.
2728
func (l *LFSLock) BeforeInsert() {
2829
l.OwnerID = l.Owner.ID
29-
l.Path = strings.ToLower(l.Path)
30+
l.Path = cleanPath(l.Path)
3031
}
3132

3233
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
3334
func (l *LFSLock) AfterLoad() {
3435
l.Owner, _ = GetUserByID(l.OwnerID)
3536
}
3637

38+
func cleanPath(p string) string {
39+
return strings.ToLower(path.Clean(p))
40+
}
41+
3742
// APIFormat convert a Release to lfs.LFSLock
3843
func (l *LFSLock) APIFormat() *api.LFSLock {
3944
return &api.LFSLock{
@@ -67,8 +72,8 @@ func CreateLFSLock(lock *LFSLock) (*LFSLock, error) {
6772

6873
// GetLFSLock returns release by given path.
6974
func GetLFSLock(repoID int64, path string) (*LFSLock, error) {
70-
path = strings.ToLower(path)
71-
rel := &LFSLock{RepoID: repoID, Path: path} //TODO Define if path should needed to be lower for windows compat ?
75+
path = cleanPath(path)
76+
rel := &LFSLock{RepoID: repoID, Path: path}
7277
has, err := x.Get(rel)
7378
if err != nil {
7479
return nil, err

0 commit comments

Comments
 (0)