Skip to content

Commit

Permalink
bugfix: allow a maximum key length of 65534 in PSR-16 decorator
Browse files Browse the repository at this point in the history
To avoid having PCRE compilation error regarding `number too big`, we have to limit the maximum key length of the decorator. This will allow us to keep the performance benefits of `preg_match` while still allowing more than the initial 64 characters limit.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Aug 8, 2021
1 parent 9ab6ad1 commit 4ddd065
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Psr/SimpleCache/SimpleCacheDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function is_object;
use function is_scalar;
use function is_string;
use function min;
use function preg_match;
use function preg_quote;
use function sprintf;
Expand Down Expand Up @@ -472,6 +473,6 @@ private function memoizeMaximumKeyLengthCapability(StorageInterface $storage, Ca
));
}

$this->maximumKeyLength = $maximumKeyLength;
$this->maximumKeyLength = min($maximumKeyLength, self::PCRE_MAXIMUM_QUANTIFIER_LENGTH - 1);
}
}
15 changes: 15 additions & 0 deletions test/Psr/SimpleCache/SimpleCacheDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use function array_keys;
use function iterator_to_array;
use function preg_match;
use function sprintf;
use function str_repeat;

Expand Down Expand Up @@ -1152,4 +1153,18 @@ public function testWillUsePcreMaximumQuantifierLengthIfAdapterAllowsMoreThanTha
));
$decorator->has($key);
}

public function testPcreMaximumQuantifierLengthWontResultInCompilationError(): void
{
self::assertEquals(
0,
preg_match(
sprintf(
'/^.{%d,}$/',
SimpleCacheDecorator::PCRE_MAXIMUM_QUANTIFIER_LENGTH
),
''
)
);
}
}

0 comments on commit 4ddd065

Please sign in to comment.