Skip to content

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

Open
@Kilbourne

Description

@Kilbourne

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, '/' )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions