Skip to content

Commit

Permalink
Fix Smi exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Apr 23, 2024
1 parent 2a3f690 commit 2c95999
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Code/Converters/SmiConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function fileContentToInternalFormat($file_content, $original_file_conten
$i++;
}
}
if (!isset($internal_format[$i - 1]['end'])) {
if (isset($internal_format[$i - 1]['start']) && !isset($internal_format[$i - 1]['end'])) {
$internal_format[$i - 1]['end'] = $internal_format[$i - 1]['start'] + 1;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/formats/SmiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Done\Subtitles\Code\Converters\SmiConverter;
use Done\Subtitles\Code\Helpers;
use Done\Subtitles\Code\UserException;
use Done\Subtitles\Subtitles;
use PHPUnit\Framework\TestCase;
use Helpers\AdditionalAssertionsTrait;
Expand Down Expand Up @@ -192,6 +193,28 @@ public function testNonEnglishWords()
$this->assertInternalFormatsEqual($expected, $actual);
}

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

$actual = Subtitles::loadFromString('
<SAMI>
<HEAD>
<STYLE TYPE="text/css">
<!-- Generated by KMPlayer
.[Local] Masked Avengers.srt
-->
</STYLE>
</HEAD>
<BODY>
<SYNC Start=20000><P Class=[Local] Masked Avengers.srt >&nbsp;
<SYNC Start=20000><P Class=[Local] Masked Avengers.srt >&nbsp;
<SYNC Start=20000><P Class=[Local] Masked Avengers.srt >&nbsp;
</BODY>
</SAMI>
')->getInternalFormat();
}

// ---------------------------------- private ----------------------------------------------------------------------

private static function fileContent()
Expand Down

0 comments on commit 2c95999

Please sign in to comment.