[wp-trac] [WordPress Trac] #62355: WP sets REQUEST_URI to an invalid value if it's not set

WordPress Trac noreply at wordpress.org
Tue Dec 10 13:56:00 UTC 2024


#62355: WP sets REQUEST_URI to an invalid value if it's not set
--------------------------+------------------------------
 Reporter:  kkmuffme      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------

Comment (by siliconforks):

 Replying to [ticket:62355 kkmuffme]:
 > https://github.com/WordPress/wordpress-develop/blame/trunk/src/wp-
 includes/load.php#L39

 I don't really see the issue here.  The current code is simply
 initializing the `$_SERVER['REQUEST_URI']` variable to the empty string
 (if it is not already set).  The empty string is not a valid value in this
 case, but programmers initialize variables to invalid values all the time.
 For example, a programmer may define a variable `$foobar` with the line
 `$foobar = null;` - by itself, that is not a bug, although it could
 possibly lead to a bug at some later point in the code.

 Is there some scenario where having `$_SERVER['REQUEST_URI']` set to the
 empty string leads to some bug, warning, etc., somewhere else in the code?

 > This is invalid, since REQUEST_URI is always at least / and cannot be an
 empty string (you can test it, even for https://example.com it will be / -
 or read https://datatracker.ietf.org/doc/html/rfc3986, which shows it's
 possibly that it can be empty, but in that case PHP would not set the
 $_SERVER variable, therefore in context of PHP it's impossible it's an
 empty string for a valid request, unless someone incorrectly modifies it -
 like WP in this case)

 Yes, it's impossible for `$_SERVER['REQUEST_URI']` to be an empty string
 for a valid request, but looking at the [https://github.com/WordPress
 /wordpress-develop/commit/cab7d51114801722e3fb01a94b0558d262514bae commit
 message] for the commit above, the change was made in order to handle
 situations where WordPress is run from the command-line (and so there is
 no valid request).

 Is there a problem with setting `$_SERVER['REQUEST_URI']` to the empty
 string in such cases?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62355#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list