From 8c8ae6bbfbd8331f71dea7e89ae371bcf44caa96 Mon Sep 17 00:00:00 2001 From: Emir Aganovic Date: Sun, 5 May 2024 00:31:39 +0200 Subject: [PATCH] fix: sip uri must consider slashes as valid uri --- sip/parse_uri.go | 11 +++++++++-- sip/parse_uri_test.go | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) 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{}