Skip to content

Commit bfcf293

Browse files
I18N: Correctly invalidate language file paths in WP_Textdomain_Registry.
Since the cache key in `::get_language_files_from_path()` is based on a path that always includes a trailing slash, the path in `::invalidate_mo_files_cache()` should include the trailing slash as well. Includes adjusting the test expectations accordingly. Follow-up to [57287], [57290], [57298]. See #58919. git-svn-id: https://develop.svn.wordpress.org/trunk@57299 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9d7bc51 commit bfcf293

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/wp-includes/class-wp-textdomain-registry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public function invalidate_mo_files_cache( $upgrader, $hook_extra ) {
237237
foreach ( $translation_types as $type ) {
238238
switch ( $type ) {
239239
case 'plugin':
240-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' );
240+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
241241
break;
242242
case 'theme':
243-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' );
243+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
244244
break;
245245
default:
246-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' );
246+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
247247
break;
248248
}
249249
}

tests/phpunit/tests/l10n/wpTextdomainRegistry.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public function set_up() {
1919
}
2020

2121
public function tear_down() {
22-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar' ), 'translations' );
23-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' );
24-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' );
25-
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' );
22+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' );
23+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
24+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' );
25+
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' );
2626

2727
parent::tear_down();
2828
}
@@ -100,10 +100,10 @@ public function test_get_language_files_from_path_caches_results() {
100100
*/
101101
public function test_get_language_files_from_path_short_circuit() {
102102
add_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
103-
$result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' );
103+
$result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' );
104104
remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
105105

106-
$cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' );
106+
$cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' );
107107

108108
$this->assertEmpty( $result );
109109
$this->assertFalse( $cache );
@@ -113,9 +113,9 @@ public function test_get_language_files_from_path_short_circuit() {
113113
* @covers ::invalidate_mo_files_cache
114114
*/
115115
public function test_invalidate_mo_files_cache() {
116-
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' );
117-
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes' );
118-
$this->instance->get_language_files_from_path( WP_LANG_DIR );
116+
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' );
117+
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes/' );
118+
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/' );
119119

120120
$this->instance->invalidate_mo_files_cache(
121121
null,
@@ -144,9 +144,9 @@ public function test_invalidate_mo_files_cache() {
144144
)
145145
);
146146

147-
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ) );
148-
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' ) );
149-
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' ) );
147+
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) );
148+
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) );
149+
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) );
150150
}
151151

152152
public function data_domains_locales() {

0 commit comments

Comments
 (0)