Skip to content

Commit

Permalink
fix: sip uri must consider slashes as valid uri
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed May 4, 2024
1 parent 0e1fece commit 8c8ae6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sip/parse_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "*" {
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions sip/parse_uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 8c8ae6b

Please sign in to comment.