Introduce a binary-safe wrapper for strlen() and use it in seems_utf8(), utf8_uri_encode(), and wp_read_image_metadata().
Use binary-safe POMO_Reader::strlen() in MO::export_to_file_handle(). fixes #28162. Built from https://develop.svn.wordpress.org/trunk@28806 git-svn-id: http://core.svn.wordpress.org/trunk@28615 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2b8460af62
commit
9ceb642b2a
|
@ -290,7 +290,7 @@ function wp_read_image_metadata( $file ) {
|
|||
$caption = trim( $iptc['2#120'][0] );
|
||||
if ( empty( $meta['title'] ) ) {
|
||||
// Assume the title is stored in 2:120 if it's short.
|
||||
if ( strlen( $caption ) < 80 )
|
||||
if ( mbstring_binary_safe_strlen( $caption ) < 80 )
|
||||
$meta['title'] = $caption;
|
||||
else
|
||||
$meta['caption'] = $caption;
|
||||
|
@ -327,7 +327,7 @@ function wp_read_image_metadata( $file ) {
|
|||
}
|
||||
|
||||
if ( ! empty( $exif['ImageDescription'] ) ) {
|
||||
if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) {
|
||||
if ( empty( $meta['title'] ) && mbstring_binary_safe_strlen( $exif['ImageDescription'] ) < 80 ) {
|
||||
// Assume the title is stored in ImageDescription
|
||||
$meta['title'] = trim( $exif['ImageDescription'] );
|
||||
if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) {
|
||||
|
|
|
@ -481,7 +481,7 @@ function shortcode_unautop( $pee ) {
|
|||
* @return bool True if $str fits a UTF-8 model, false otherwise.
|
||||
*/
|
||||
function seems_utf8($str) {
|
||||
$length = strlen($str);
|
||||
$length = mbstring_binary_safe_strlen($str);
|
||||
for ($i=0; $i < $length; $i++) {
|
||||
$c = ord($str[$i]);
|
||||
if ($c < 0x80) $n = 0; # 0bbbbbbb
|
||||
|
@ -705,7 +705,7 @@ function utf8_uri_encode( $utf8_string, $length = 0 ) {
|
|||
$num_octets = 1;
|
||||
$unicode_length = 0;
|
||||
|
||||
$string_length = strlen( $utf8_string );
|
||||
$string_length = mbstring_binary_safe_strlen( $utf8_string );
|
||||
for ($i = 0; $i < $string_length; $i++ ) {
|
||||
|
||||
$value = ord( $utf8_string[ $i ] );
|
||||
|
|
|
@ -4404,6 +4404,24 @@ function reset_mbstring_encoding() {
|
|||
mbstring_binary_safe_encoding( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a binary-safe encoding to get the length of a string in bytes if func_overload is enabled.
|
||||
*
|
||||
* @see mbstring_binary_safe_encoding()
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $string The string to get the length of.
|
||||
* @return int The length of the string in bytes.
|
||||
*/
|
||||
function mbstring_binary_safe_strlen( $string ) {
|
||||
mbstring_binary_safe_encoding();
|
||||
$length = strlen( $string );
|
||||
reset_mbstring_encoding();
|
||||
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN )
|
||||
*
|
||||
|
|
|
@ -75,21 +75,23 @@ class MO extends Gettext_Translations {
|
|||
$current_addr++;
|
||||
$originals_table = chr(0);
|
||||
|
||||
$reader = new POMO_Reader();
|
||||
|
||||
foreach($entries as $entry) {
|
||||
$originals_table .= $this->export_original($entry) . chr(0);
|
||||
$length = strlen($this->export_original($entry));
|
||||
$length = $reader->strlen($this->export_original($entry));
|
||||
fwrite($fh, pack('VV', $length, $current_addr));
|
||||
$current_addr += $length + 1; // account for the NULL byte after
|
||||
}
|
||||
|
||||
$exported_headers = $this->export_headers();
|
||||
fwrite($fh, pack('VV', strlen($exported_headers), $current_addr));
|
||||
fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr));
|
||||
$current_addr += strlen($exported_headers) + 1;
|
||||
$translations_table = $exported_headers . chr(0);
|
||||
|
||||
foreach($entries as $entry) {
|
||||
$translations_table .= $this->export_translations($entry) . chr(0);
|
||||
$length = strlen($this->export_translations($entry));
|
||||
$length = $reader->strlen($this->export_translations($entry));
|
||||
fwrite($fh, pack('VV', $length, $current_addr));
|
||||
$current_addr += $length + 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue