Skip to content

Conversation

@camilleislasse
Copy link
Contributor

Problem

When uploading files to subfolders (e.g., user-uploads/2024/image.jpg), cache keys generated by MediaPropertyAccessor and MediaVariationPropertyAccessor contain forward slashes (/), which are reserved characters in PSR-6 cache implementations.

This causes errors like:

This causes validation errors with real cache adapters:
Cache key "joli_media_property_default_subfolder/file.jpg_lastModified" contains reserved characters "{}()/:"

Solution

  • Created CacheKeySanitizer helper class to sanitize cache keys by replacing PSR-6 reserved characters ({}()/\@:) with underscores
  • Applied sanitization to libraryName, path, and variation->getName() in cache key generation
  • The sanitization only affects cache keys, not the actual file paths used to access files

Testing

To test with a real cache adapter, replace the mock in tests/src/BaseTestCase.php with:

$cache = new ArrayAdapter();

This will show the cache key validation errors before the fix, and confirm they're resolved after.

@tacman tacman mentioned this pull request Nov 19, 2025
@xavierlacot xavierlacot force-pushed the fix/cache-key-reserved-characters branch from a2b7416 to 4818c3b Compare November 20, 2025 11:17
@xavierlacot
Copy link
Member

Thanks @camilleislasse for the contribution 💛

@xavierlacot xavierlacot merged commit d5f124d into jolicode:main Nov 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants