diff --git a/sip/parse_uri.go b/sip/parse_uri.go index 679559a..f750a84 100644 --- a/sip/parse_uri.go +++ b/sip/parse_uri.go @@ -29,12 +29,12 @@ func ParseUri(uriStr string, uri *Uri) (err error) { func uriStateSIP(uri *Uri, s string) (uriFSM, string, error) { if len(s) >= 4 && strings.EqualFold(s[:4], "sip:") { - return uriStateUser, s[4:], nil + return uriStateScheme, s[4:], nil } if len(s) >= 5 && strings.EqualFold(s[:5], "sips:") { uri.Encrypted = true - return uriStateUser, s[5:], nil + return uriStateScheme, s[5:], nil } if s == "*" { @@ -48,6 +48,13 @@ func uriStateSIP(uri *Uri, s string) (uriFSM, string, error) { return uriStateUser, s, nil } +func uriStateScheme(_ *Uri, s string) (uriFSM, string, error) { + // Check does uri contain slashes + // They are valid in uri but normally we cut them + s, _ = strings.CutPrefix(s, "//") + return uriStateUser, s, nil +} + func uriStateUser(uri *Uri, s string) (uriFSM, string, error) { var userend int = 0 for i, c := range s { diff --git a/sip/parse_uri_test.go b/sip/parse_uri_test.go index 44a105c..b5f248a 100644 --- a/sip/parse_uri_test.go +++ b/sip/parse_uri_test.go @@ -67,6 +67,15 @@ func TestParseUri(t *testing.T) { }) + t.Run("with sip scheme slashes", func(t *testing.T) { + // No scheme we currently allow + uri = Uri{} + str = "sip://alice@localhost:5060" + err = ParseUri(str, &uri) + require.NoError(t, err) + assert.Equal(t, "sip:alice@localhost:5060", uri.String()) + }) + t.Run("no sip scheme", func(t *testing.T) { // No scheme we currently allow uri = Uri{}