Plugins: In `plugin_basename()` normalize the file path before unresolving symlinks.

`$wp_plugin_paths` contains normalized paths, see `wp_register_plugin_realpath()`.

Props jdgrimes, voldemortensen, flyingdr, ocean90.
Fixes #29154.

git-svn-id: https://develop.svn.wordpress.org/trunk@37332 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2016-04-30 15:08:06 +00:00
parent c39a438d65
commit d62141c38d
2 changed files with 30 additions and 1 deletions

View File

@ -675,13 +675,15 @@ function remove_all_actions($tag, $priority = false) {
function plugin_basename( $file ) {
global $wp_plugin_paths;
// $wp_plugin_paths contains normalized paths.
$file = wp_normalize_path( $file );
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) {
$file = $dir . substr( $file, strlen( $realdir ) );
}
}
$file = wp_normalize_path( $file );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

View File

@ -0,0 +1,27 @@
<?php
/**
* Tests for plugin_basename()
*
* @group functions.php
* @group plugins
*/
class Tests_Plugin_Basename extends WP_UnitTestCase {
/**
* @ticket 29154
*/
function test_should_return_correct_basename_for_symlinked_plugins() {
global $wp_plugin_paths;
$old_wp_plugin_paths = $wp_plugin_paths;
$wp_plugin_paths[ WP_PLUGIN_DIR . '/a-symlinked-plugin' ] = 'C:/www/path/plugins/a-plugin';
$basename = plugin_basename( 'c:\www\path\plugins\a-plugin\plugin.php' );
$wp_plugin_paths = $old_wp_plugin_paths;
$this->assertSame( 'a-symlinked-plugin/plugin.php', $basename );
}
}