allowing empty comments

This commit is contained in:
Vadim Getmanshchuk 2023-11-30 21:55:10 -06:00 committed by Sebastian Dröge
parent b9cf88b7ec
commit d8e0283ddb

View file

@ -218,7 +218,7 @@ enum MasterPlaylistTag {
SessionKey(SessionKey), SessionKey(SessionKey),
Start(Start), Start(Start),
IndependentSegments, IndependentSegments,
Comment(String), Comment(Option<String>),
Uri(String), Uri(String),
Unknown(ExtTag), Unknown(ExtTag),
} }
@ -487,7 +487,7 @@ enum SegmentTag {
ProgramDateTime(chrono::DateTime<chrono::FixedOffset>), ProgramDateTime(chrono::DateTime<chrono::FixedOffset>),
DateRange(DateRange), DateRange(DateRange),
Unknown(ExtTag), Unknown(ExtTag),
Comment(String), Comment(Option<String>),
Uri(String), Uri(String),
} }
@ -609,10 +609,10 @@ fn ext_tag(i: &[u8]) -> IResult<&[u8], ExtTag> {
)(i) )(i)
} }
fn comment_tag(i: &[u8]) -> IResult<&[u8], String> { fn comment_tag(i: &[u8]) -> IResult<&[u8], Option<String>> {
map( map(
pair( pair(
preceded(char('#'), map_res(is_not("\r\n"), from_utf8_slice)), preceded(char('#'), opt(map_res(is_not("\r\n"), from_utf8_slice))),
take(1usize), take(1usize),
), ),
|(text, _)| text, |(text, _)| text,
@ -929,7 +929,7 @@ mod tests {
fn comment() { fn comment() {
assert_eq!( assert_eq!(
comment_tag(b"#Hello\nxxx"), comment_tag(b"#Hello\nxxx"),
Result::Ok(("xxx".as_bytes(), "Hello".to_string())) Result::Ok(("xxx".as_bytes(), Some("Hello".to_string())))
); );
} }