Skip to content

Commit e5b6fbb

Browse files
committed
Fix ssa parsing error if style contains leading or trailing whitespaces
1 parent 9c44413 commit e5b6fbb

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/ssa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ mod parse {
10061006
list: &'a Vec<&str>,
10071007
header_line: usize,
10081008
current_line: usize,
1009-
) -> Result<&'a &'a str> {
1009+
) -> Result<&'a str> {
10101010
let pos = headers
10111011
.iter()
10121012
.position(|h| {
@@ -1019,7 +1019,7 @@ mod parse {
10191019
kind: SSAErrorKind::MissingHeader(name.to_string()),
10201020
})?;
10211021

1022-
list.get(pos).ok_or(Error {
1022+
list.get(pos).map(|l| l.trim()).ok_or(Error {
10231023
line: current_line,
10241024
kind: SSAErrorKind::Parse(format!("no value for header '{}'", name)),
10251025
})

tests/ssa.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,18 @@ Style: Default,Arial,25.5,&H00FFFFFF,&H00000000,{color},&H00000000,-1,0,0,0,120,
837837
}
838838
}
839839

840+
#[test]
841+
fn styles_whitespace() {
842+
let ssa = r#"[Script Info]
843+
844+
[V4+ Styles]
845+
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
846+
Style: Default, Arial, 25.5,&H00FFFFFF,&H00000000, &H00000000 ,&H00000000,-1 ,0, 0 ,0,120,120,0,0,1,1,1,2,0000,0000,0030,0
847+
"#;
848+
849+
let _ = SSA::parse(ssa).unwrap();
850+
}
851+
840852
#[test]
841853
fn events_missing_header() {
842854
let ssa = r#"[Script Info]

0 commit comments

Comments
 (0)