From 5318f2ad7b388ebbbe1207fa1efa8e617f7dfa4a Mon Sep 17 00:00:00 2001 From: GyeongHo Kim Date: Tue, 30 Jul 2024 22:27:53 +0900 Subject: [PATCH] feat: add regex check. related to #26 - if user calls Dial method with an url that does not URL encoded, return error to remind. --- format/rtspv2/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/format/rtspv2/client.go b/format/rtspv2/client.go index 397f1e7..e985027 100644 --- a/format/rtspv2/client.go +++ b/format/rtspv2/client.go @@ -14,6 +14,7 @@ import ( "log" "net" "net/url" + "regexp" "strconv" "strings" "time" @@ -521,6 +522,11 @@ func (client *RTSPClient) parseURL(rawURL string) error { } username := l.User.Username() password, _ := l.User.Password() + pattern := `[ !#$%&'()*+,/:;=?@\[\]]` + re := regexp.MustCompile(pattern) + if re.MatchString(username) || re.MatchString(password) { + return errors.New("please url encode username and password") + } l.User = nil if l.Port() == "" { l.Host = fmt.Sprintf("%s:%s", l.Host, "554")