Opened 8 years ago
Last modified 5 weeks ago
#38479 new defect (bug)
Need to check utf8_encode() is available before use.
Reported by: | gitlost | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
The DOM/XML extension isn't necessarily installed on some distros so use of utf8_encode()
should be checked for availability first. It's not checked in wp_read_image_metadata()
in "wp-admin/includes/image.php" (where I encountered its lack on a Ubuntu 16.04 PHP 7 server), introduced in [36429] and [36430], nor in wxr_cdata()
in "wp-admin/includes/export.php", introduced in the distant past.
(Also it does ISO-8859-1 not Windows-1252 so more than likely not that good in the image situation anyway.)
Change History (5)
This ticket was mentioned in Slack in #core-media by desrosj. View the logs.
7 years ago
#2
@
7 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
This ticket was mentioned in PR #7118 on WordPress/wordpress-develop by @debarghyabanerjee.
6 weeks ago
#4
- Keywords has-patch added; needs-patch removed
Trac Ticket: Core-38479
## Overview
- This pull request addresses the issue of handling the
utf8_encode()
function in WordPress, particularly when the DOM/XML extension is not available or utf8_encode() itself is not present. This function has been deprecated and is not guaranteed to be available on all server configurations. This change ensures compatibility and avoids potential errors related to its use in the functionswp_read_image_metadata()
andwxr_cdata()
.
## Problem Statement
- The use of
utf8_encode()
in the following functions may lead to compatibility issues:
wp_read_image_metadata()
inwp-admin/includes/image.php
wxr_cdata()
inwp-admin/includes/export.php
- On servers where the DOM/XML extension is not installed or where utf8_encode() is not available, the current implementation may fail. Furthermore,
utf8_encode()
is deprecated and should be replaced with a more reliable approach.
## Solution
Check for Function Availability
: Before usingutf8_encode()
, check if it is available using thefunction_exists()
function. This prevents errors on servers whereutf8_encode()
is not defined.
Deprecation Handling
: Replaceutf8_encode()
with the recommendedmb_convert_encoding()
function, which provides better support for different character encodings and is not deprecated.
## Benefits
Improved Compatibility
: Ensures that WordPress functions do not fail on servers whereutf8_encode()
is not available or where the DOM/XML extension is not installed.
Future-Proof
: By replacingutf8_encode()
withmb_convert_encoding()
, we align with modern standards and avoid issues related to deprecated functions.
Enhanced Reliability
: The use ofmb_convert_encoding()
provides more robust handling of different character encodings.
## Notes
- This change is backward-compatible and ensures that existing functionality remains unaffected while improving overall reliability.
@gitlost are you interested in making a patch for this?