Skip to content

Commit

Permalink
Merge pull request #26 from jaminh/header-parsing-fix
Browse files Browse the repository at this point in the history
Fix SIP header parsing
  • Loading branch information
synesthesiam authored Jan 27, 2025
2 parents 5fdfce6 + 76f3ad9 commit 6f615ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/test_sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_parse_header_for_uri_no_space_name():
assert endpoint.uri == "sip:[email protected]"


def test_parse_header_for_uri_no_space_between_name():
endpoint = SipEndpoint("Test<sip:[email protected]>")
assert endpoint.description == "Test"
assert endpoint.uri == "sip:[email protected]"


def test_parse_header_for_uri_no_space_between_quoted_name():
endpoint = SipEndpoint('"Test Endpoint"<sip:[email protected]>')
assert endpoint.description == "Test Endpoint"
assert endpoint.uri == "sip:[email protected]"


def test_parse_header_for_uri_no_username():
endpoint = SipEndpoint("Test <sip:example.com>")
assert endpoint.description == "Test"
Expand Down
2 changes: 1 addition & 1 deletion voip_utils/sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SipEndpoint:

def __post_init__(self):
header_pattern = re.compile(
r'\s*((?P<description>\b\w+\b|"[^"]+")\s+)?<?(?P<uri>sips?:[^>]+)>?.*'
r'\s*((?P<description>\b\w+\b|"[^"]+")\s*)?<?(?P<uri>sips?:[^>]+)>?.*'
)
header_match = header_pattern.match(self.sip_header)
if header_match is not None:
Expand Down

0 comments on commit 6f615ad

Please sign in to comment.