Add cleanup, minor fixes

This commit is contained in:
blankhex committed 2026-10-21 20:13:27 +03:00
1 parent 97dc0a3570
commit 284e4e7080
7 files changed
+107 -15

No files matched your search

+24 -2
View File
@@ -6,6 +6,28 @@ import (
"time"
)
// sanitizeRoomName trims a room name and collapses any character that is not
// allowed in a room name into a single dash, stripping leading/trailing dashes.
// Case is preserved because Jitsi room names are case-sensitive.
func sanitizeRoomName(value string) string {
var builder strings.Builder
builder.Grow(len(value))
previousDash := false
for _, r := range strings.TrimSpace(value) {
allowed := (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '-' || r == '_'
if allowed {
builder.WriteRune(r)
previousDash = false
continue
}
if !previousDash {
builder.WriteByte('-')
previousDash = true
}
}
return strings.Trim(builder.String(), "-")
}
type joinRoomRequest struct {
Room string `json:"room"`
}
@@ -54,7 +76,7 @@ func (h *Handler) joinRoom(w http.ResponseWriter, r *http.Request) {
return
}
room := strings.TrimSpace(req.Room)
room := sanitizeRoomName(req.Room)
if room == "" {
writeError(w, http.StatusBadRequest, "room is required")
return
@@ -93,7 +115,7 @@ func (h *Handler) joinRoom(w http.ResponseWriter, r *http.Request) {
func (h *Handler) deleteRecentRoom(w http.ResponseWriter, r *http.Request) {
u := userFromRequest(r)
room := strings.TrimSpace(r.PathValue("room"))
room := sanitizeRoomName(r.PathValue("room"))
if room == "" {
writeError(w, http.StatusBadRequest, "room is required")
return