mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-26 04:23:22 +02:00
[cherry-pick] Allow empty path in redirect_url (#20237)
Allow empty path in redirect_url fixes #20226 Signed-off-by: stonezdj <daojunz@vmware.com> Co-authored-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
parent
a7f62f3cff
commit
a823845d76
@ -313,11 +313,11 @@ func ValidateCronString(cron string) error {
|
|||||||
// sort.Slice(input, func(i, j int) bool {
|
// sort.Slice(input, func(i, j int) bool {
|
||||||
// return MostMatchSorter(input[i].GroupName, input[j].GroupName, matchWord)
|
// return MostMatchSorter(input[i].GroupName, input[j].GroupName, matchWord)
|
||||||
// })
|
// })
|
||||||
|
//
|
||||||
// a is the field to be used for sorting, b is the other field, matchWord is the word to be matched
|
// a is the field to be used for sorting, b is the other field, matchWord is the word to be matched
|
||||||
// the return value is true if a is less than b
|
// the return value is true if a is less than b
|
||||||
// for example, search with "user", input is {"harbor_user", "user", "users, "admin_user"}
|
// for example, search with "user", input is {"harbor_user", "user", "users, "admin_user"}
|
||||||
// it returns with this order {"user", "users", "admin_user", "harbor_user"}
|
// it returns with this order {"user", "users", "admin_user", "harbor_user"}
|
||||||
|
|
||||||
func MostMatchSorter(a, b string, matchWord string) bool {
|
func MostMatchSorter(a, b string, matchWord string) bool {
|
||||||
// exact match always first
|
// exact match always first
|
||||||
if a == matchWord {
|
if a == matchWord {
|
||||||
@ -333,7 +333,7 @@ func MostMatchSorter(a, b string, matchWord string) bool {
|
|||||||
return len(a) < len(b)
|
return len(a) < len(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLocalPath checks if path is local
|
// IsLocalPath checks if path is local, includes the empty path
|
||||||
func IsLocalPath(path string) bool {
|
func IsLocalPath(path string) bool {
|
||||||
return strings.HasPrefix(path, "/") && !strings.HasPrefix(path, "//")
|
return len(path) == 0 || (strings.HasPrefix(path, "/") && !strings.HasPrefix(path, "//"))
|
||||||
}
|
}
|
||||||
|
@ -501,6 +501,7 @@ func TestIsLocalPath(t *testing.T) {
|
|||||||
{"other_site1", args{"//www.myexample.com"}, false},
|
{"other_site1", args{"//www.myexample.com"}, false},
|
||||||
{"other_site2", args{"https://www.myexample.com"}, false},
|
{"other_site2", args{"https://www.myexample.com"}, false},
|
||||||
{"other_site", args{"http://www.myexample.com"}, false},
|
{"other_site", args{"http://www.myexample.com"}, false},
|
||||||
|
{"empty_path", args{""}, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user