Skip to content

Commit d2038ac

Browse files
committed
feat: add new option: lengthLimit
If the input is longer than this, it's like aborted. Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent 7f4c94d commit d2038ac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/SequenceMatcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ final class SequenceMatcher
9393
'ignoreCase' => false,
9494
'ignoreLineEnding' => false,
9595
'ignoreWhitespace' => false,
96+
'lengthLimit' => 2000,
9697
];
9798

9899
private array $matchingBlocks = [];
@@ -129,7 +130,7 @@ public function setOptions(array $options): static
129130
$needRerunChainB = $this->isAnyOptionChanged(
130131
$this->options,
131132
$options,
132-
['ignoreCase', 'ignoreLineEnding', 'ignoreWhitespace'],
133+
['ignoreCase', 'ignoreLineEnding', 'ignoreWhitespace', 'lengthLimit'],
133134
);
134135

135136
$this->options = $options + self::$defaultOptions;
@@ -671,7 +672,7 @@ private function chainB(): static
671672
$this->b2j[$char] = $this->b2j[$char] ?? [];
672673

673674
if (
674-
$length >= 1000
675+
$length >= $this->options['lengthLimit']
675676
&& \count($this->b2j[$char]) * 100 > $length
676677
&& $char !== self::APPENDED_HELPER_LINE
677678
) {

0 commit comments

Comments
 (0)