#20449 closed defect (bug) (fixed)
get_home_path() error on windows with different home and site_url values
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Permalinks | Version: | 3.3.1 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | knut@… |
Description
get_home_path() was always returning a root directory reference '/'
Environment:
IIS 7.5, FCGI, PHP 5.3.10, WP 3.3.1
Walking through
I'll just run through what's happening to the values below:
// for ref, script_filename is
//$_SERVER["SCRIPT_FILENAME"] = 'D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php'
function get_home_path() {
$home = get_option( 'home' );
// $home='http://site.com'
$siteurl = get_option( 'siteurl' );
// $siteurl = 'http://site.com/wp'
if ( $home != '' && $home != $siteurl ) {
$wp_path_rel_to_home = str_replace($home, '', $siteurl);
// $wp_path_rel_to_home = '/wp'
$pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
// $pos = FALSE
$home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
// $home_path = ''
$home_path = trailingslashit( $home_path );
// $home_path = '/'
} else {
$home_path = ABSPATH;
}
return $home_path;
// returns '/'
}
Suggest adding the following line
$wp_path_rel_to_home = str_replace('/', DIRECTORY_SEPARATOR, $wp_path_rel_to_home);
Diff:
--- a/wp/wp-admin/includes/file.php
+++ b/wp/wp-admin/includes/file.php
@@ -81,6 +81,7 @@ function get_home_path() {
$siteurl = get_option( 'siteurl' );
if ( $home != '' && $home != $siteurl ) {
$wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */
+ $wp_path_rel_to_home = str_replace('/', DIRECTORY_SEPARATOR, $wp_path_rel_to_home); // replaces url slashs with backslashes when needed
$pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home);
$home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos);
$home_path = trailingslashit( $home_path );
--
Attachments (4)
Change History (18)
SergeyBiryukov — 13 months ago
comment:2
SergeyBiryukov — 13 months ago
- Keywords has-patch added
- Owner set to dd32
- Resolution set to fixed
- Status changed from new to closed
In [21224]:
comment:5
WraithKenny — 6 months ago
If on D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php with a subfolder install ($wp_path_rel_to_home = '/wp') the desired result is D:\root\vhosts\site\httpdocs\ but we get D:\root\vhosts\site\httpdocs\wp\
This causes the .htaccess file to be written to the WordPress Address rather then the Site Address.
The strripos hits the wp in wp-admin so in the special case that the subfolder is wp (like Mark's skeleton) this patch doesn't work well.
Should this be reopened, or a new ticket?
comment:7
WraithKenny — 6 months ago
$pos = stripos( ... fixes in case of wp folder install.
comment:8
WraithKenny — 6 months ago
#18768 is the reason for the strripos instead of stripos. We probably need something more complicated then just the first or last occurrence.
WraithKenny — 6 months ago
comment:9
WraithKenny — 6 months ago
20449.2.patch uses trailingslashit on $wp_path_rel_to_home (to search against a directory), which prevents /wp/ from matching /wp.dev or /wp-admin etc.
comment:10
SergeyBiryukov — 6 months ago
Tested 20449.2.patch, looks good to me.
comment:11
nacin — 6 months ago
- Keywords commit added
Added ryan's tests in [1146].
The tests fail without, and pass with, 20449.2.patch.
dd32 has been traveling over the last few days, so would like to get him to look at this. But happy to have this committed without that review for now.
comment:12
dd32 — 6 months ago
- Resolution set to fixed
- Status changed from reopened to closed
In 22800:
comment:13
dd32 — 6 months ago
'doh, copied the wrong patch submitter! Sorry WraithKenny!
comment:14
WraithKenny — 6 months ago
No Prob :-)

For some reason, $_SERVER['SCRIPT_FILENAME'] contains forward slashes on my Windows install:
So the bug didn't reproduce as is. ABSPATH contains backslashes though:
The patch also handles #10447.