Fix character encoding detection in CSV exporter for PHP 8.1 (#38648)

This commit is contained in:
Barry Hughes 2023-06-09 14:32:09 -07:00 committed by GitHub
commit 902454a40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix character encoding detection in CSV exporter for PHP 8.1

View File

@ -398,8 +398,10 @@ abstract class WC_CSV_Exporter {
$use_mb = function_exists( 'mb_convert_encoding' ); $use_mb = function_exists( 'mb_convert_encoding' );
if ( $use_mb ) { if ( $use_mb ) {
$encoding = mb_detect_encoding( $data, 'UTF-8, ISO-8859-1', true ); $is_valid_utf_8 = mb_check_encoding( $data, 'UTF-8' );
$data = 'UTF-8' === $encoding ? $data : utf8_encode( $data ); if ( ! $is_valid_utf_8 ) {
$data = mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' );
}
} }
return $this->escape_data( $data ); return $this->escape_data( $data );