Skip to content

Commit

Permalink
Closes #5815 Correctly clear cache for URLs whose permalink contains …
Browse files Browse the repository at this point in the history
…uppercase letters in non-latin alphabets (#5852)

Co-authored-by: Rémy Perona <[email protected]>
  • Loading branch information
jeawhanlee and remyperona authored Jun 1, 2023
1 parent 3b6300e commit 50dcab4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion inc/functions/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ function rocket_clean_files( $urls, $filesystem = null ) {
do_action( 'before_rocket_clean_files', $urls ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals

foreach ( $urls as $url ) {

/**
* Fires before the cache file is deleted.
*
Expand All @@ -596,7 +595,25 @@ function rocket_clean_files( $urls, $filesystem = null ) {

if ( ! empty( $parsed_url['host'] ) ) {
foreach ( _rocket_get_cache_dirs( $parsed_url['host'], $cache_path ) as $dir ) {
// Decode url path.
$url_chunks = explode( '/', $parsed_url['path'] );
$matches = preg_grep( '/%/', $url_chunks );

if ( ! empty( $matches ) ) {
$parsed_url['path'] = rawurldecode( $parsed_url['path'] );
}

// Encode Non-latin characters if found in url path.
if ( false !== preg_match_all( '/(?<non_latin>[^\x00-\x7F]+)/', $parsed_url['path'], $matches ) ) {
$cb_encode_non_latin = function( $non_latin ) {
return strtolower( rawurlencode( $non_latin ) );
};

$parsed_url['path'] = str_replace( $matches['non_latin'], array_map( $cb_encode_non_latin, $matches['non_latin'] ), $parsed_url['path'] );
}

$entry = $dir . $parsed_url['path'];

// Skip if the dir/file does not exist.
if ( ! $filesystem->exists( $entry ) ) {
continue;
Expand Down

0 comments on commit 50dcab4

Please sign in to comment.