mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-14 02:13:10 -06:00
Check for empty alias parameter and fix route URL
Signed-off-by: Ross Schulman <ross@rbs.io>
This commit is contained in:
parent
4fd5aaf93d
commit
47e05f20b7
|
|
@ -15,16 +15,16 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/util"
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RoomAliasToID converts the queried alias into a room ID and returns it
|
// RoomAliasToID converts the queried alias into a room ID and returns it
|
||||||
|
|
@ -33,9 +33,15 @@ func RoomAliasToID (
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
cfg config.Dendrite,
|
cfg config.Dendrite,
|
||||||
aliasAPI api.RoomserverAliasAPI,
|
aliasAPI api.RoomserverAliasAPI,
|
||||||
roomAlias string,
|
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
_, domain, err := gomatrixserverlib.SplitID('#', httpReq.FormValue("alias"))
|
roomAlias := httpReq.FormValue("alias")
|
||||||
|
if roomAlias == "" {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 400,
|
||||||
|
JSON: jsonerror.BadJSON("Must supply room alias parameter."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
|
|
@ -52,7 +58,7 @@ var resp gomatrixserverlib.RespDirectory
|
||||||
return httputil.LogThenError(httpReq, err)
|
return httputil.LogThenError(httpReq, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryRes.RoomID == "") {
|
if queryRes.RoomID == "" {
|
||||||
// TODO: List servers that are aware of this room alias
|
// TODO: List servers that are aware of this room alias
|
||||||
resp = gomatrixserverlib.RespDirectory{
|
resp = gomatrixserverlib.RespDirectory{
|
||||||
RoomID: queryRes.RoomID,
|
RoomID: queryRes.RoomID,
|
||||||
|
|
|
||||||
|
|
@ -113,12 +113,11 @@ v1fedmux.Handle("/version", common.MakeExternalAPI(
|
||||||
},
|
},
|
||||||
)).Methods("GET")
|
)).Methods("GET")
|
||||||
|
|
||||||
v1fedmux.Handle("/query/directory/?room_alias={alias}", common.MakeFedAPI(
|
v1fedmux.Handle("/query/directory/", common.MakeFedAPI(
|
||||||
"federation_query_room_alias", cfg.Matrix.ServerName, keys,
|
"federation_query_room_alias", cfg.Matrix.ServerName, keys,
|
||||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||||
vars := mux.Vars(httpReq)
|
|
||||||
return RoomAliasToID(
|
return RoomAliasToID(
|
||||||
httpReq, federation, cfg, aliasAPI, vars["alias"],
|
httpReq, federation, cfg, aliasAPI,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)).Methods("Get")
|
)).Methods("Get")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue