Skip to content

Commit

Permalink
Stricter vtt parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Dec 22, 2023
1 parent 69e04da commit 7096b25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Code/Converters/VttConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function fileContentToInternalFormat($file_content, $original_file_conten

foreach ($lines as $line) {
$parts = TxtConverter::getLineParts($line, $colon_count, 2);
if ($seen_first_timestamp === false && $parts['start'] && $parts['end']) {
if ($seen_first_timestamp === false && $parts['start'] && $parts['end'] && Helpers::strContains($line, '-->')) {
$seen_first_timestamp = true;
}
if (!$seen_first_timestamp) {
Expand Down
17 changes: 17 additions & 0 deletions tests/formats/VttTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,21 @@ public function testClientFile()
->getInternalFormat();
$this->assertEquals($expected, $actual);
}

public function testClientFileNoArrow()
{
$this->expectException(UserException::class);
$given = <<< TEXT
WEBVTT
00:00:07:17 - 00:00:08:14
Hi team Canada.
TEXT;
$actual = (new Subtitles())->loadFromString($given)->getInternalFormat();
$expected = (new Subtitles())
->add(7.17, 8.14, 'Hi team Canada.')
->getInternalFormat();
$this->assertEquals($expected, $actual);
}
}

0 comments on commit 7096b25

Please sign in to comment.