Skip to content

Commit b518fad

Browse files
authored
Merge pull request #125 from jiaozifs/fix/fix_obj_prefix
fix: fix obj path start with '/'
2 parents 7f1208c + e14abd6 commit b518fad

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

controller/validator/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
ReValidRef = regexp.MustCompile(`^\w+/?\w+$`)
1313
ReValidRepo = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_\-]{1,61}[a-zA-Z0-9]$`)
1414
ReValidUser = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{1,28}[a-zA-Z0-9]$`)
15-
ReValidPath = regexp.MustCompile(`^(?:/?[^\x00-\x1F\\/:*?"<>|]+/)*[^\x00-\x1F\\/:*?"<>|]+(\.[^\x00-\x1F\\/:*?"<>|]+)?$`)
15+
ReValidPath = regexp.MustCompile(`^[^\x00/:*?"<>|]*/?([^/\s\x00:*?"<>|]+/)*[^/\s\x00:*?"<>|]+(?:\.[a-zA-Z0-9]+)?$`)
1616

1717
// RepoNameBlackList forbid repo name, reserve for routes
1818
RepoNameBlackList = []string{"repository", "repositories", "wip", "wips", "object", "objects", "commit", "commits", "ref", "refs", "repo", "repos", "user", "users"}

controller/validator/validate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestValidateUsername(t *testing.T) {
9898

9999
func TestValidateObjectPath(t *testing.T) {
100100
//Validate Obj Path
101-
validObjectPaths := []string{"path/to/object", "file.txt", "folder/file.txt", "我的图片.png", "我的文件/我的应用.exe", "私のビデオ.mp3, /video.mp3, /path/pic.png"}
101+
validObjectPaths := []string{"path/to/object", "file.txt", "folder/file.txt", "我的图片.png", "我的文件/我的应用.exe", "私のビデオ.mp3", "/video.mp3", "/path/pic.png"}
102102
for _, path := range validObjectPaths {
103103
err := ValidateObjectPath(path)
104104
if err != nil {

0 commit comments

Comments
 (0)