Make WordPress Core

Opened 8 years ago

Last modified 7 years ago

#40339 new defect (bug)

If $home_path=='wp' then WP::parse_request() will remove 'wp' from 'wp-json/wc/v1/products' in $pathinfo

Reported by: magenta-cuda's profile Magenta Cuda Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Rewrite Rules Keywords: needs-patch needs-testing
Focuses: Cc:

Description

I have installed WordPress in a subdirectory 'wp' so $home_path is 'wp'. The statement

pathinfo = preg_replace( $home_path_regex, '', $pathinfo );

is called with arguments

$home_path_regex = '|^wp|i'
$pathinfo = 'wp-json/wc/v1/products'

and returns

$pathinfo = '-json/wc/v1/products'

Since, $_SERVER[ 'PATH_INFO' ] is the trailing part of the path wouldn't the leading home path be already removed?

Here is the $_SERVER variable:

$_SERVER=Array
(
    [SERVER_SOFTWARE] => PHP 5.6.30 Development Server
    [REQUEST_URI] => /wp/wp-json/wc/v1/products
    [DOCUMENT_ROOT] => C:\\WWW
    [REMOTE_ADDR] => 192.168.1.113
    [REMOTE_PORT] => 54207
    [SERVER_PROTOCOL] => HTTP/1.1
    [SERVER_NAME] => me.local.com
    [SERVER_PORT] => 80
    [REQUEST_METHOD] => GET
    [SCRIPT_NAME] => /wp/index.php
    [SCRIPT_FILENAME] => C:\\WWW\\wp\\index.php
    [PATH_INFO] => /wp-json/wc/v1/products
    [PHP_SELF] => /wp/index.php/wp-json/wc/v1/products
    [HTTP_HOST] => me.local.com
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,en-AU;q=0.6
    [HTTP_COOKIE] => wp-settings-1=libraryContent%3Dbrowse%26mfold%3Do%26editor%3Dhtml%26posts_list_mode%3Dexcerpt%26widgets_access%3Don%26post_dfw%3Don%26hidetb%3D1; wp-settings-time-1=1489742056; wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_82a92e8b6fd4f1e7bd35e69acfebe645=mc%7C1491295996%7ClSYWOrX5ljiNvjMUuOsdx3Hqd3B4PsyM6sdhaHx3VHB%7C0f85cc8928c44377d339344bd93f970151fb018ad0623b09964e252bc6104127
    [REQUEST_TIME_FLOAT] => 1491131923.8711
    [REQUEST_TIME] => 1491131923
)

Change History (1)

#1 @dd32
7 years ago

  • Keywords needs-patch needs-testing added

Hey @Magenta-Cuda and welcome back to Trac.

In most cases, PHP_INFO should only be the trailing component, however that's not always the case unfortunately.
IIS (particularly older versions I think) actually pass the whole REQUEST_URI in there - see https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx

I'm wondering if we can change this regex to effectively be:

$home_path_regex = '!^wp(?:/|$)!i'
$pathinfo = 'wp-json/wc/v1/products'
Note: See TracTickets for help on using tickets.