[wp-trac] [WordPress Trac] #55741: Check the value of WP_ENVIRONMENT_TYPE before using it

WordPress Trac noreply at wordpress.org
Mon May 16 06:44:01 UTC 2022


#55741: Check the value of WP_ENVIRONMENT_TYPE before using it
----------------------------+-----------------------------
 Reporter:  dd32            |      Owner:  (none)
     Type:  enhancement     |     Status:  new
 Priority:  low             |  Milestone:  Awaiting Review
Component:  Bootstrap/Load  |    Version:
 Severity:  trivial         |   Keywords:  2nd-opinion
  Focuses:                  |
----------------------------+-----------------------------
 The constant `WP_ENVIRONMENT_TYPE` as used by
 [https://developer.wordpress.org/reference/functions/wp_get_environment_type/
 wp_get_environment_type()] doesn't validate the value of the constant
 before overriding the environment value.

 This is problematic, especially during unit testing, as it becomes
 impossible to alter the environment during the unit test run, if the
 environment is forcefully setting the constant
 ([https://github.com/WordPress/gutenberg/issues/41083 such as through wp-
 env]).

 While it could be possibly beneficial to validate that the value is within
 the whitelist, at least checking it's non-empty may ease testing for some
 configurations:
 {{{#!diff
 Index: load.php
 ===================================================================
 --- load.php    (revision 52988)
 +++ load.php    (working copy)
 @@ -227,7 +227,7 @@
         }

         // Fetch the environment from a constant, this overrides the
 global system variable.
 -       if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
 +       if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE ) {
                 $current_env = WP_ENVIRONMENT_TYPE;
         }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55741>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list