mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
restore support for cameras with percent sign in password, broken after 1e612f2
This commit is contained in:
@@ -3,6 +3,7 @@ package base
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -11,10 +12,17 @@ import (
|
||||
// control attributes.
|
||||
type URL url.URL
|
||||
|
||||
var escapeRegexp = regexp.MustCompile(`^(.+?)://(.*?)@(.*?)/(.*?)$`)
|
||||
|
||||
// ParseURL parses a RTSP URL.
|
||||
func ParseURL(s string) (*URL, error) {
|
||||
s = strings.ReplaceAll(s, "%25", "%")
|
||||
s = strings.ReplaceAll(s, "%", "%25")
|
||||
// https://github.com/golang/go/issues/30611
|
||||
m := escapeRegexp.FindStringSubmatch(s)
|
||||
if m != nil {
|
||||
m[3] = strings.ReplaceAll(m[3], "%25", "%")
|
||||
m[3] = strings.ReplaceAll(m[3], "%", "%25")
|
||||
s = m[1] + "://" + m[2] + "@" + m[3] + "/" + m[4]
|
||||
}
|
||||
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -22,11 +23,12 @@ func TestURLParse(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"ipv6 stateless",
|
||||
`rtsp://[fe80::a8f4:3219:f33e:a072%wl0]:8554/proxied`,
|
||||
`rtsp://user:pa%23ss@[fe80::a8f4:3219:f33e:a072%wl0]:8554/prox%23ied`,
|
||||
&URL{
|
||||
Scheme: "rtsp",
|
||||
Host: "[fe80::a8f4:3219:f33e:a072%wl0]:8554",
|
||||
Path: "/proxied",
|
||||
Path: "/prox#ied",
|
||||
User: url.UserPassword("user", "pa#ss"),
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
Reference in New Issue
Block a user