streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit df412ed36264c687bce78048956d6f93b4695800
parent 0282f4221f089db5a75bf993a81f7e444253a418
Author: Oliver Lowe <o@olowe.co>
Date:   Mon,  1 Jul 2024 18:11:24 +1000

sdp: strip phone number of redundant chars

Makes it easier to compare values.

Diffstat:
Msdp/sdp.go | 13++++++++++---
Msdp/sdp_test.go | 2+-
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/sdp/sdp.go b/sdp/sdp.go @@ -21,8 +21,6 @@ type Session struct { Info string URI *url.URL Email *mail.Address - // TODO(otl): can we do any sanitisation here? at least delete spaces or something...? - // The number "+1 617 555-6011" is semantically equal to "+16175556011" Phone string // TODO(otl): add rest of fields } @@ -117,7 +115,7 @@ First: session.Email = addr onext = fchars[3:] case "p": - session.Phone = v + session.Phone = cleanPhone(v) onext = nil default: return nil, fmt.Errorf("expected one of %v, found %q", onext, k) @@ -126,6 +124,15 @@ First: return &session, sc.Err() } +// cleanPhone returns the phone number in s stripped of "-" and space +// characters. Since "+1 617 555-6011" is semantically equal to +// "+16175556011", storing the number in the latter form lets us test for +// equality more easily. +func cleanPhone(s string) string { + s = strings.ReplaceAll(s, " ", "") + return strings.ReplaceAll(s, "-", "") +} + func parseOrigin(line string) (Origin, error) { fields := strings.Fields(line) if len(fields) != 6 { diff --git a/sdp/sdp_test.go b/sdp/sdp_test.go @@ -26,7 +26,7 @@ func TestReadSession(t *testing.T) { Path: "/home.html", }, Email: &mail.Address{"Jane Doe", "jane@jdoe.example.com"}, - Phone: "+1 617 555-6011", + Phone: "+16175556011", }, }, {