Make WordPress Core

Changeset 37983


Ignore:
Timestamp:
07/06/2016 09:44:58 AM (10 years ago)
Author:
ocean90
Message:

Plugins: In plugin_basename() sort plugin paths before resolving symlinks.

arsort() sorts the paths reverse-alphabetically while preserving the keys. It results in a longer path being listed before a shorter one with the same base directory(ies).

Props jdgrimes, ocean90.
Fixes #28441.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/plugin.php

    r37911 r37983  
    732732        $file = wp_normalize_path( $file );
    733733
     734        arsort( $wp_plugin_paths );
    734735        foreach ( $wp_plugin_paths as $dir => $realdir ) {
    735736                if ( strpos( $file, $realdir ) === 0 ) {
  • trunk/tests/phpunit/tests/functions/pluginBasename.php

    r37719 r37983  
    1010
    1111        /**
     12         * @var array
     13         */
     14        protected $wp_plugin_paths_backup;
     15
     16        /**
     17         * Normalized path to plugin directory.
     18         *
     19         * @var string
     20         */
     21        protected $wp_plugin_path;
     22
     23        public function setUp() {
     24                parent::setUp();
     25
     26                $this->wp_plugin_paths_backup = $GLOBALS['wp_plugin_paths'];
     27                $this->wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );
     28        }
     29
     30        public function tearDown() {
     31                $GLOBALS['wp_plugin_paths'] = $this->wp_plugin_paths_backup;
     32
     33                parent::tearDown();
     34        }
     35
     36        /**
    1237         * @ticket 29154
    1338         */
    14         function test_should_return_correct_basename_for_symlinked_plugins() {
     39        function test_return_correct_basename_for_symlinked_plugins() {
    1540                global $wp_plugin_paths;
    1641
    17                 $old_wp_plugin_paths = $wp_plugin_paths;
    18 
    19                 $wp_plugin_paths[ wp_normalize_path( WP_PLUGIN_DIR ) . '/a-symlinked-plugin' ] = 'C:/www/path/plugins/a-plugin';
     42                $wp_plugin_paths = array(
     43                        $this->wp_plugin_path . '/a-symlinked-plugin' => 'C:/www/path/plugins/a-plugin',
     44                );
    2045
    2146                $basename = plugin_basename( 'c:\www\path\plugins\a-plugin\plugin.php' );
    22 
    23                 $wp_plugin_paths = $old_wp_plugin_paths;
    24 
    2547                $this->assertSame( 'a-symlinked-plugin/plugin.php', $basename );
    2648        }
     49
     50        /**
     51         * @ticket 28441
     52         */
     53        function test_return_correct_basename_for_symlinked_plugins_with_path_conflicts() {
     54                global $wp_plugin_paths;
     55
     56                $wp_plugin_paths = array(
     57                        $this->wp_plugin_path . '/plugin' => '/Users/me/Dropbox/Development/Repositories/plugin',
     58                        $this->wp_plugin_path . '/trunk' => '/Users/me/Dropbox/Development/Repositories/plugin/trunk',
     59                );
     60
     61                $basename = plugin_basename( '/Users/me/Dropbox/Development/Repositories/plugin/trunk/plugin.php' );
     62                $this->assertSame( 'trunk/plugin.php', $basename );
     63        }
    2764}
Note: See TracChangeset for help on using the changeset viewer.