Make WordPress Core

Opened 12 years ago

Last modified 8 years ago

#20849 closed defect (bug)

'ABSPATH' Invalid with Windows Servers — at Version 4

Reported by: admintiger's profile admintiger Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Filesystem API Keywords:
Focuses: Cc:

Description (last modified by johnbillion)

The following code defines 'ABSPATH' with mixed backward and forward slashes (like this: 'C:\public\www.example.com/') six places within WordPress when run on a Windows server:

define('ABSPATH', dirname(__FILE__) . '/');

Additional path strings with forward slashes are subsequently concatenated many places in the core, in plugins, and sometimes in themes, resulting in many invalid filepaths similar to the following example:

C:\public\www.example.com/wp-includes/shortcodes.php

Mixed slashes like that cause a variety of malfunctions generally when WordPress is used on Windows servers, but especially when minifying and/or caching plugins are used.

I suggest changing:

define('ABSPATH', dirname(__FILE__) . '/');

to:

define('ABSPATH', str_replace(chr(92), '/', dirname(__FILE__)) . '/');

in each of the following places to correct those problems:

\wp-config-sample.php -> Line 87

\wp-load.php -> Line 22

\wp-admin\load-scripts.php -> Line 11

\wp-admin\load-styles.php -> Line 11

\wp-admin\setup-config.php -> Line 39

\wp-admin\gears-manifest.php -> Line 17

Change History (4)

#1 @knutsp
12 years ago

  • Cc knut@… added
  • Severity changed from major to normal

I haven't seen any malfunctions related to this mix of directory separators. Windows allows and respects both. So why is a path like

C:\public\www.example.com/wp-includes/shortcodes.php

invalid?

I don't use minifying plugins, but if they fail I would consider it a bug in the plugin, not WordPress core.

For caching I only use Wincache on Windows servers.

As the backslash is not legal in a file- or dirname on Unix/Linux (?) I guess that suggested change won't break anything. It will add some consistency in that all paths will use the same separator from left to right. This may make some file handling plugins start working on Windows servers without being tested on Windows.

#2 @GaryJ
12 years ago

The use of the PHP constant DIRECTORY_SEPARATOR would be better.

#3 @knutsp
12 years ago

Using DIRECTORY_SEPARATOR instead of chr(92) in the suggested str_replace function would be completely pointless. On non-Windows you will then replace all occurrences of "/" with "/".

WordPress core have standardized on using "/" for creating paths, and that's how it should be, regardless of the actual DIRECTORY_SEPARATOR.

The only usefulness of constant DIRECTORY_SEPARATOR is when parsing paths generated by the system, if you prefer not to substitute those before parsing.

#4 @johnbillion
12 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.