1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

feat: improve URI parsing in webfinger endpoint

This commit is contained in:
Aravinth Manivannan 2024-04-01 21:28:56 +05:30 committed by Earl Warren
parent 855d75d0bc
commit 8273f8b756

View file

@ -70,13 +70,57 @@ func WebfingerQuery(ctx *context.Context) {
return return
} }
parts := strings.Split(resource.Path, "/") p, _ := strings.CutPrefix(resource.Path, "/")
if len(parts) < 2 { // fragment[0] is empty space, fragment[1] may be username p, _ = strings.CutSuffix(p, "/")
ctx.Error(http.StatusBadRequest) if len(p) == 0 {
ctx.Error(http.StatusNotFound)
return return
} }
u, err = user_model.GetUserByName(ctx, parts[1]) parts := strings.Split(p, "/")
switch len(parts) {
case 1: // user
u, err = user_model.GetUserByName(ctx, parts[0])
// case 2: // repository
// ctx.Error(http.StatusNotFound)
// return
//
// case 3:
// switch parts[2] {
// case "issues":
// ctx.Error(http.StatusNotFound)
// return
//
// case "pulls":
// ctx.Error(http.StatusNotFound)
// return
//
// case "projects":
// ctx.Error(http.StatusNotFound)
// return
//
// default:
// ctx.Error(http.StatusNotFound)
// return
//
// }
// case 4:
// if parts[3] == "teams" {
// ctx.Error(http.StatusNotFound)
// return
//
// } else {
// ctx.Error(http.StatusNotFound)
// return
// }
default:
ctx.Error(http.StatusNotFound)
return
}
default: default:
ctx.Error(http.StatusBadRequest) ctx.Error(http.StatusBadRequest)
return return