Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 34fbbe6

Browse files
Fix Media attribute lookup
1 parent 01bd185 commit 34fbbe6

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/description/media.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ pub struct MediaDescription {
6060

6161
impl MediaDescription {
6262
/// attribute returns the value of an attribute and if it exists
63-
pub fn attribute(&self, key: &str) -> Option<&String> {
63+
pub fn attribute(&self, key: &str) -> Option<Option<&str>> {
6464
for a in &self.attributes {
6565
if a.key == key {
66-
return a.value.as_ref();
66+
return Some(a.value.as_ref().map(|s| s.as_ref()));
6767
}
6868
}
6969
None
@@ -239,3 +239,31 @@ impl fmt::Display for MediaName {
239239
write!(f, "{}", s.join(" "))
240240
}
241241
}
242+
243+
#[cfg(test)]
244+
mod tests {
245+
use super::MediaDescription;
246+
247+
#[test]
248+
fn test_attribute_missing() {
249+
let media_description = MediaDescription::default();
250+
251+
assert_eq!(media_description.attribute("recvonly"), None);
252+
}
253+
254+
#[test]
255+
fn test_attribute_present_with_no_value() {
256+
let media_description =
257+
MediaDescription::default().with_property_attribute("recvonly".to_owned());
258+
259+
assert_eq!(media_description.attribute("recvonly"), Some(None));
260+
}
261+
262+
#[test]
263+
fn test_attribute_present_with_value() {
264+
let media_description =
265+
MediaDescription::default().with_value_attribute("ptime".to_owned(), "1".to_owned());
266+
267+
assert_eq!(media_description.attribute("ptime"), Some(Some("1")));
268+
}
269+
}

0 commit comments

Comments
 (0)