Skip to content

Commit

Permalink
Fix vtt exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Aug 27, 2023
1 parent 4dc2654 commit 7fac608
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Code/Converters/VttConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ protected static function vttTimeToInternal($vtt_time)
// parts[0] could be mm:ss or hh:mm:ss format -> always use hh:mm:ss
$parts[0] = substr_count($parts[0], ':') == 2 ? $parts[0] : '00:'.$parts[0];

if (!isset($parts[1])) {
throw new UserException("Time doesn't have milliseconds: " . $vtt_time);
}
$only_seconds = strtotime("1970-01-01 {$parts[0]} UTC");
$milliseconds = (float)('0.' . $parts[1]);

Expand Down
15 changes: 15 additions & 0 deletions tests/formats/VttTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ public function testParsesFileWithCue()
$this->assertInternalFormatsEqual($expected, $actual);
}

public function testExceptionIfWrongTimestamp()
{
$this->expectException(UserException::class);

$input_vtt_file_content = <<< TEXT
WEBVTT
1
00:00:00.00 --> 00:00:01.o0
a
TEXT;

Subtitles::loadFromString($input_vtt_file_content)->getInternalFormat();
}

public function testNoExceptionWhenEmptyFile()
{
$this->expectException(UserException::class);
Expand Down

0 comments on commit 7fac608

Please sign in to comment.