Skip to content

Commit

Permalink
Revert "fix: the file path must start with /"
Browse files Browse the repository at this point in the history
This reverts commit 7a05e26.
  • Loading branch information
Brownjy committed Jan 25, 2024
1 parent 7a05e26 commit ff993c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion controller/validator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
ReValidRef = regexp.MustCompile(`^\w+/?\w+$`)
ReValidRepo = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_\-]{1,61}[a-zA-Z0-9]$`)
ReValidUser = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{1,28}[a-zA-Z0-9]$`)
ReValidPath = regexp.MustCompile(`^/(?:[^\x00-\x1F\\/:*?"<>|]+/)*[^\x00-\x1F\\/:*?"<>|]+(\.[^\x00-\x1F\\/:*?"<>|]+)?$`)
ReValidPath = regexp.MustCompile(`^(?:/?[^\x00-\x1F\\/:*?"<>|]+/)*[^\x00-\x1F\\/:*?"<>|]+(\.[^\x00-\x1F\\/:*?"<>|]+)?$`)

// RepoNameBlackList forbid repo name, reserve for routes
RepoNameBlackList = []string{"repository", "repositories", "wip", "wips", "object", "objects", "commit", "commits", "ref", "refs", "repo", "repos", "user", "users"}
Expand Down
13 changes: 6 additions & 7 deletions controller/validator/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestValidateUsername(t *testing.T) {

func TestValidateObjectPath(t *testing.T) {
//Validate Obj Path
validObjectPaths := []string{"/path/to/object", "/file.txt", "/folder/file.txt", "/我的图片.png", "/我的文件/我的应用.exe", "/私のビデオ.mp3"}
validObjectPaths := []string{"path/to/object", "file.txt", "folder/file.txt", "我的图片.png", "我的文件/我的应用.exe", "私のビデオ.mp3, /video.mp3, /path/pic.png"}
for _, path := range validObjectPaths {
err := ValidateObjectPath(path)
if err != nil {
Expand All @@ -111,12 +111,11 @@ func TestValidateObjectPath(t *testing.T) {
path string
error string
}{
{"path/with/null", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"/path/with/null\x00character", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"/path/with/invalid/characters/:", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"/path/with/invalid/characters/*", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"/path/with/invalid/characters/\"", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"/path/with/invalid/characters/<?", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"path/with/null\x00character", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"path/with/invalid/characters/:", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"path/with/invalid/characters/*", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"path/with/invalid/characters/\"", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
{"path/with/invalid/characters/<?", "invalid object path: it must not contain null characters or NTFS forbidden characters"},
}

for _, testCase := range invalidObjectPaths {
Expand Down

0 comments on commit ff993c7

Please sign in to comment.