Opened 13 months ago
Closed 12 months ago
#63865 closed enhancement (fixed)
Replace warning-suppression with error-handler in _wp_can_use_pcre_u
| Reported by: | dmsnell | Owned by: | dmsnell |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.9 |
| Component: | Charset | Version: | 6.9 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Follow-up to [45611].
See #47632.
A WPCS “ignore” comment was added to _wp_can_use_pcre_u() to silence alarms about the use of warning-suppression, which generally is problematic. While this silenced WPCS, it left the issue in Core.
Warning suppression can be problematic:
- It can mask and conflate unintended warnings.
- It bypasses existing error-handling.
- Some errors are not suppressed.
In this case, the WPCS rule is actually helpful in pointing out risk, though it has not led to updating the code. The function can implement a specific error-handler to focus on the specific detection it wants to make: whether Unicode PCRE patterns are supported.
Change History (8)
This ticket was mentioned in PR #9576 on WordPress/wordpress-develop by @dmsnell.
13 months ago
#1
- Keywords has-patch added
This ticket was mentioned in PR #9618 on WordPress/wordpress-develop by prashantsuwalka-orange.
12 months ago
#2
This patch removes the use of @preg_match warning suppression in the
_wp_can_use_pcre_u() function and replaces it with an explicit error handler.
Changes:
- Removed the @ operator from preg_match.
- Added error detection using error_get_last() to log any PCRE/u detection failures.
- Preserves cached results and supports reset functionality.
- Manual overrides (TRUE/FALSE) continue to work as expected.
- Fully tested in local WordPress development environment to ensure all code paths function correctly.
This improves security and debugging by avoiding silenced warnings while maintaining the
original functionality of the function.
Trac ticket: 63865
This ticket was mentioned in Slack in #core by cyberorange. View the logs.
12 months ago
#5
@
12 months ago
- Resolution fixed
- Status closed → reopened
Reopening to update sanitize_file_name() to call this instead of performing its own check-with-error-suppression.
This ticket was mentioned in PR #9678 on WordPress/wordpress-develop by @dmsnell.
12 months ago
#6
Trac ticket: Core-63865.
The sanitize_file_name() function attempts to make its own manual detection of Unicode PCRE support, but WordPress already provides a more-robust method of doing so. In order to avoid re-computation, it also stores the result in a static var inside the function. That check is already stored in a static var, however, inside _wp_can_use_pcre_u() check and so the extra cache is largely ineffective.
This patch leans on the recently-updated _wp_can_use_pcre_u() check and removes the superfluous static var.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: Core-63865
Trac ticket: