Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache is not purged when the path of cache folder contains a char that is part of the regular expression syntax #6982

Open
Kilbourne opened this issue Sep 19, 2024 · 0 comments · May be fixed by #6983

Comments

@Kilbourne
Copy link

To Reproduce

  1. Install wordpress in a path containing a char that is part of the regular expression syntax. Example: install at /releases/2024-09-02T11:32:23+0000/ so the cache folder will be at /releases/2024-09-02T11:32:23+0000/wp-content/cache/wp-rocket/
  2. Purge the cache via the admin bar ( or other method)
  3. The cache is not purged

Why it happens

the function rocket_clean_files uses the function _rocket_get_cache_dirs at

foreach ( _rocket_get_cache_dirs( $parsed_url['host'], $cache_path ) as $dir ) {

_rocket_get_cache_dirs searches the folders by regex:

$iterator = new IteratorIterator(
new FilesystemIterator( $cache_path )
);
} catch ( Exception $e ) {
return [];
}
$regex = sprintf(
'/%1$s%2$s(.*)/i',
_rocket_normalize_path( $cache_path, true ),
$url_host
);
try {
$entries = new RegexIterator( $iterator, $regex );
} catch ( Exception $e ) {

But _rocket_normalize_path( $cache_path, true ) only escapes the slash but not other characters.

It should be replaced by preg_quote( $cache_path, '/' )

Kilbourne added a commit to Kilbourne/wp-rocket that referenced this issue Sep 19, 2024
@piotrbak piotrbak added this to the 3.17.1 milestone Sep 27, 2024
@piotrbak piotrbak removed this from the 3.17.1 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants