#55741 closed enhancement (fixed)
Check the value of WP_ENVIRONMENT_TYPE before using it
Reported by: | dd32 | Owned by: | desrosj |
---|---|---|---|
Milestone: | 6.1 | Priority: | low |
Severity: | trivial | Version: | |
Component: | Bootstrap/Load | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
The constant WP_ENVIRONMENT_TYPE
as used by 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 (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:
-
load.php
227 227 } 228 228 229 229 // Fetch the environment from a constant, this overrides the global system variable. 230 if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {230 if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE ) { 231 231 $current_env = WP_ENVIRONMENT_TYPE; 232 232 }
Attachments (3)
Change History (14)
This ticket was mentioned in PR #2730 on WordPress/wordpress-develop by itzmekhokan.
3 years ago
#2
- Keywords has-patch added
#3
@
3 years ago
Went ahead and removed double code from class-wp-debug-data.php and upgraded the checks.
#4
@
3 years ago
added patch 2, as the is_string is not needed anymore due to the in_array strict checker
#5
@
3 years ago
About the string strict check. You might add (via filter) a non string environment and if you have defined it at your wp-config.php the check will pass.
This is an edge case however, if you want to cover this in the wp_environment_is_allowed
function you will need to add an is_string
check
#6
@
2 years ago
- Keywords commit added; 2nd-opinion removed
- Owner set to desrosj
- Status changed from new to reviewing
Thanks for the patches!
While there is some potential for consolidation and flexibility through new filters, I think that deserves a broader discussion.
I think that 55741.diff is preferred here as it simply fixes the specific issue being reported without additional refactoring.
#9
@
2 years ago
Yes this will suffice @desrosj
I went perhaps a bit too far introducing the filter.
Will still love if the if/else/check was just 1 central function as having duplicate code will/might lead to issues later on.
#10
@
2 years ago
@ramon-fincken I’m still open to exploring it, but think it’s best in a new ticket.
As WP_ENVIRONMENT_TYPE variable declaration is a string type, so there must be some condition checking of values as well.
Trac ticket: 55741