Skip to content

Commit

Permalink
Corner cases fixed (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Kuzmin <i.kuzmin@webinar.ru>
  • Loading branch information
kuzmig and Igor Kuzmin authored Feb 22, 2024
1 parent 4a14998 commit c438e16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions sdp/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (d *Decoder) media(m *Media, f byte, v string) error {
func (d *Decoder) format(m *Media, a *Attr) error {
p, ok := d.fields(a.Value, 2)
if !ok {
return errFormat
return nil
}
var (
pt = p[0]
Expand Down Expand Up @@ -283,7 +283,7 @@ func (d *Decoder) connection(v string) (*Connection, error) {
}
c := new(Connection)
c.Network, c.Type, c.Address = p[0], p[1], p[2]
p, ok = d.split(c.Address, '/', 3)
p, _ = d.split(c.Address, '/', 3)
switch c.Type {
case TypeIPv4:
if len(p) > 2 {
Expand All @@ -299,7 +299,6 @@ func (d *Decoder) connection(v string) (*Connection, error) {
return nil, err
}
c.Address, c.TTL = p[0], int(ttl)
p = append(p[:1], p[2:]...)
}
case TypeIPv6:
if len(p) > 1 {
Expand Down
8 changes: 6 additions & 2 deletions sdp/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ func (w writer) media(m *Media) writer {
if f := m.FormatDescr; f != "" {
w = w.sp().str(f)
} else {
for _, it := range m.Format {
w = w.sp().int(int64(it.Payload))
if len(m.Format) > 0 {
for _, it := range m.Format {
w = w.sp().int(int64(it.Payload))
}
} else if m.PortNum == 0 {
w = w.sp().str("0")
}
}
if m.Information != "" {
Expand Down

0 comments on commit c438e16

Please sign in to comment.