You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The documentation states that invalid cache keys always throw an exception #28
The documentation states that an invalid cache key throws a Psr\Cache\InvalidArgumentException:
reference/adapter.md: "Cache keys must follow the PSR-6 rules: an empty key, or a key containing one of the reserved characters {}()/\@:, throws a Psr\Cache\InvalidArgumentException."
reference/tasks/set_task.md: "If the input does not override the placeholder key, the empty key throws a Psr\Cache\InvalidArgumentException."
This is only true when assertions are enabled. Symfony cache adapters (ArrayAdapter, and every adapter based on AbstractAdapterTrait: filesystem, Redis, APCu...) only validate the keys with assert(): with zend.assertions=-1 (production php.ini), an empty key or a key with reserved characters is silently accepted and the item is stored.
$ php -d zend.assertions=1 test.php
Symfony\Component\Cache\Exception\InvalidArgumentException (for each adapter and key)
$ php -d zend.assertions=-1 test.php
(no exception, the items are stored and can be read back)
Found with the CI of #27 (setup-php uses the production php.ini): a test expecting the exception on an empty key failed.
Tested on main (e88cf4f), symfony/cache 7.4 / 8.1, PHP 8.5.
Proposed fix
Document that the key validation belongs to the adapter, and that Symfony adapters only reject invalid keys when assertions are enabled: in production, a placeholder key '' not overridden by the input stores / reads every item under the same empty key.
Activity
Merge pull request #29 from cleverage/28