From 8b5520927385655e24a5e229eee6688231fed622 Mon Sep 17 00:00:00 2001 From: Yami Odymel Date: Wed, 18 Jun 2025 23:27:39 +0800 Subject: [PATCH] Fixed #125, sanitize Username with [^a-zA-Z0-9_-] and remove whitespace --- entity/entity.go | 10 ++++++++++ manager/manager.go | 1 + 2 files changed, 11 insertions(+) diff --git a/entity/entity.go b/entity/entity.go index acd23eb..0f57d9a 100644 --- a/entity/entity.go +++ b/entity/entity.go @@ -1,5 +1,10 @@ package entity +import ( + "regexp" + "strings" +) + // Event represents the type of event for the channel. type Event = string @@ -20,6 +25,11 @@ type ChannelConfig struct { CreatedAt int64 `json:"created_at"` } +func (c *ChannelConfig) Sanitize() { + c.Username = regexp.MustCompile(`[^a-zA-Z0-9_-]`).ReplaceAllString(c.Username, "") + c.Username = strings.TrimSpace(c.Username) +} + // ChannelInfo represents the information about a channel, // mostly used for the template rendering. type ChannelInfo struct { diff --git a/manager/manager.go b/manager/manager.go index d675c33..bb9659d 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -88,6 +88,7 @@ func (m *Manager) LoadConfig() error { // CreateChannel starts monitoring an M3U8 stream func (m *Manager) CreateChannel(conf *entity.ChannelConfig, shouldSave bool) error { + conf.Sanitize() ch := channel.New(conf) // prevent duplicate channels