Skip to content

Commit

Permalink
feat: add new option: lengthLimit
Browse files Browse the repository at this point in the history
If the input is longer than this, it's like aborted.

Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed May 21, 2023
1 parent bfbc3f6 commit 6501645
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ final class SequenceMatcher
'ignoreCase' => false,
'ignoreLineEnding' => false,
'ignoreWhitespace' => false,
'lengthLimit' => 2000,
];

/**
Expand Down Expand Up @@ -138,7 +139,7 @@ public function setOptions(array $options): self
$needRerunChainB = $this->isAnyOptionChanged(
$this->options,
$options,
['ignoreCase', 'ignoreLineEnding', 'ignoreWhitespace']
['ignoreCase', 'ignoreLineEnding', 'ignoreWhitespace', 'lengthLimit']
);

$this->options = $options + self::$defaultOptions;
Expand Down Expand Up @@ -680,7 +681,7 @@ private function chainB(): self
$this->b2j[$char] = $this->b2j[$char] ?? [];

if (
$length >= 1000
$length >= $this->options['lengthLimit']
&& \count($this->b2j[$char]) * 100 > $length
&& $char !== self::APPENDED_HELPER_LINE
) {
Expand Down

0 comments on commit 6501645

Please sign in to comment.