diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/SSA.pm index 0f52da6..e48c0db 100644 --- a/lib/Subtitle/SSA.pm +++ b/lib/Subtitle/SSA.pm @@ -44,11 +44,11 @@ sub parse { study $line; # check section switch - if ($line =~ m/^\s*\[(.+)\]\s*/o) { - my $name = $1; + if ($line =~ m/^\s*\[\s*([a-z0-9+ ]+)\s*\]\s*$/io) { + my $name = lc($1); if ($name =~ m{script \s+ info}oix) { $section = 'header'; - } elsif ($name =~ m{events}oi) { + } elsif ($name eq 'events') { $section = 'events'; } elsif ($name =~ m{v4(\+)? \s+ styles}oix) { $section = 'styles'; @@ -57,9 +57,10 @@ sub parse { $self->log(warn => "Set type to $self->{type} because of line $linenum (fallback mode)"); } } else { - undef $section; - $self->log(debug => "Unknown section at line $linenum: $line"); + $section = 'unknown'; + $self->log(warn => "Unknown section at line $linenum: $line"); } + $self->log(debug => "section changed to [$section] at line $linenum"); next; } #