Skip to content

Commit 8af07da

Browse files
committed
Fix bad file parsing
1 parent 95694b8 commit 8af07da

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Subtitles.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ public function loadFromString(string $string, bool $strict = true): self
435435
}
436436
}
437437

438+
foreach ($internal_format as $row) {
439+
foreach ($row['lines'] as $line) {
440+
if (strlen($line) > 2000) {
441+
throw new UserException('One text line has over 2000 symbols');
442+
}
443+
}
444+
}
445+
438446
$this->internal_format = array_values($internal_format);
439447
return $this;
440448
}

tests/OtherTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,12 @@ public function testNotStrictModeRemovesAllBlocks()
143143
$actual = (new Subtitles())->loadFromString('00:00:00 01:00:00 help', false)->getInternalFormat();
144144
$this->assertInternalFormatsEqual([], $actual);
145145
}
146+
147+
public function testDoesntAllowLongText()
148+
{
149+
$this->expectExceptionMessage('One text line has over 2000 symbols');
150+
151+
$long_text = str_repeat('a', 2001);
152+
(new Subtitles())->loadFromString($long_text)->content('srt');
153+
}
146154
}

0 commit comments

Comments
 (0)