Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 22 months ago

#28811 closed defect (bug) (invalid)

Mixed slashes in windows paths cause issues downstream

Reported by: alightner Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Filesystem API Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

There are issues caused downstream via the mixed slashes in windows paths. While the initial calls to require_once() may cope fine with the mixed slashes, it is still beneficial to construct the paths correctly in the first place. For example if someone uses a search and replace call to manipulate the path and the slashes don't match in the search or target string the substitution may fail unexpectedly on windows, giving odd behavior when the user tries to access that new path.

This brings me to a common complaint with the nextgen gallery:

http://wordpress.org/support/topic/updated-wp-and-nextgen-gallery-to-207 (10 months ago)
http://wordpress.org/support/topic/wp-crash-after-moved-to-other-server-1 (1 month ago)

I know that someone complained about this once before here: #20849 and it was closed as "invalid", but I would like to re-raise this issue, with an alternative solution. I do understand that no one wants to make unnecessary search/replace calls to "correct" the slash for the Linux machines. However, I also hope that you can see the benefit with building the paths correctly in the first place with the DIRECTORY_SEPARATOR, so that things behave more consistently for both linux and windows users alike.

My proposed fix is simple enough:
Edit both: {DOCROOT}\wp_load.php & {DOCROOT}\wp_config.php (and any other place that defines ABSPATH)

Find: define( 'ABSPATH', dirname(__FILE__) . '/' );
Replace with: define('ABSPATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);

Be careful with the following "finds" you are looking for things that end in DIR NOT URL!!!

Edit {DOCROOT}\wp-includes\default_constants.php
Find: define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
Replace with: define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' );
Find: define( 'PLUGINDIR', 'wp-content/plugins' );
Replace with: define( 'PLUGINDIR', 'wp-content'.DIRECTORY_SEPARATOR .'plugins' );
Find: define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );
Replace with: define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . DIRECTORY_SEPARATOR .'mu-plugins' );
Find: define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
Replace with: define( 'MUPLUGINDIR', 'wp-content'.DIRECTORY_SEPARATOR .'mu-plugins' );

I can't say for certain how many places where the DIRECTORY_SEPARATOR is needed, but you get the idea what to do to fix it from that sampling of edits.


Change History (4)

#1 @SergeyBiryukov
7 years ago

  • Description modified (diff)

Related: #15598, #16457, #17494, #20849.

#2 @SergeyBiryukov
7 years ago

#29726 was marked as a duplicate.

#3 @dd32
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

As mixed paths are perfectly OK on all PHP platforms, and DIRECTORY_SEPARATOR is only really useful for display purposes, I'm marking this as invalid.

Anywhere in core where a path needs to be compared, wp_normalize_path() is used, plugins should use the same method for cross-platform compatibility. (See all the above tickets for discussion).

Last edited 7 years ago by SergeyBiryukov (previous) (diff)

#4 @SergeyBiryukov
22 months ago

#48099 was marked as a duplicate.

Note: See TracTickets for help on using tickets.