Skip to content

Commit 06e006e

Browse files
committed
Fix txt exception
1 parent 933ab27 commit 06e006e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Code/Converters/TxtConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public function fileContentToInternalFormat($file_content, $original_file_conten
2424
$file_content2 = trim($file_content);
2525
$file_content2 = preg_replace("/\n+/", "\n", $file_content2);
2626
$lines = mb_split("\n", $file_content2);
27+
if ($lines === false) {
28+
throw new UserException("Can't get lines from this file");
29+
}
2730

2831
if (!self::doesFileUseTimestamps($lines)) {
2932
if (self::areEmptyLinesUsedAsSeparators($file_content)) {

tests/formats/TxtTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Formats;
44

55
use Done\Subtitles\Code\Converters\TxtConverter;
6+
use Done\Subtitles\Code\UserException;
67
use Done\Subtitles\Subtitles;
78
use PHPUnit\Framework\TestCase;
89
use Helpers\AdditionalAssertionsTrait;
@@ -436,6 +437,17 @@ public function testParsesTimestampsWhenTheyAreIdentical()
436437
], $actual);
437438
}
438439

440+
public function testWhenCantGetLinesReturnsUserException()
441+
{
442+
$this->expectException(UserException::class);
443+
444+
Subtitles::loadFromString('
445+
00:00:00.00,00:00:01.00
446+
rz´2_ÿ¿®ŽÖÅâÖÉ
447+
<b>a</b>
448+
')->getInternalFormat();
449+
}
450+
439451
// ---------------------------------- private ----------------------------------------------------------------------
440452

441453
private static function generatedSubtitles()

0 commit comments

Comments
 (0)