WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 17 months ago

#18768 closed defect (bug) (fixed)

WordPress may not return correct $home_path when installed in a subdirectory

Reported by: ptahdunbar Owned by: dd32
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.2
Component: Filesystem API Keywords: has-patch 3.4-early
Focuses: Cc:

Description

I've got a local install of WordPress set within a subdirectory of the root (like all the cool kids).

Here's the file path:
/Users/ptah/Sites/vhosts/wp.dev/www/wp/

After installing and setting pretty permalinks, WordPress wasn't able to create the .htaccess file even though it had write access to the root folder.

I traced the bug down to get_home_path() where it trys to guess the WordPress directory by strpos() the script path against the relative wp path. Starting the comparison from left to right, it stopped at the first wp it found giving me the following home path:
/Users/ptah/Sites/vhosts/

Well, that's wrong. It should be:
/Users/ptah/Sites/vhosts/wp.dev/www/wp/

Patch fixes this by using strrpos() instead which stops at the last occurrence of the needle.
Given that it's matching against $_SERVER['SCRIPT_FILENAME'], it's more logical to work from the script path of WordPress than the other way around which may or may not contain duplicate matches.

Attachments (1)

ticket.18768.diff (638 bytes) - added by ptahdunbar 3 years ago.

Download all attachments as: .zip

Change History (6)

ptahdunbar3 years ago

comment:1 volcanicpixels3 years ago

  • Component changed from General to Filesystem

I just tested the patch - works great.

comment:2 nacin2 years ago

  • Keywords 3.4-early added
  • Milestone changed from Awaiting Review to Future Release
  • Owner set to dd32
  • Status changed from new to assigned
  • Version changed from 3.3 to 3.2

Looks good to me. Unit tests might be helpful for this. Assigning to dd32.

comment:3 dd322 years ago

  • Milestone changed from Future Release to 3.4

A simple way to trigger this is to install into a folder of the same name as your username.

Verified, patch works.

comment:4 dd322 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In [19697]:

Fix edge case in get_home_path() where the incorrect path may be returned. Props ptahdunbar. Fixes #18768

comment:5 WraithKenny17 months ago

See #20449 fails for /wp/wp-admin/options-permalink.php since wp-admin is the last occurrence.

Note: See TracTickets for help on using tickets.