Make WordPress Core

Changeset 28806


Ignore:
Timestamp:
06/23/2014 02:47:08 PM (10 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r28589 r28806  
    291291                if ( empty( $meta['title'] ) ) {
    292292                    // Assume the title is stored in 2:120 if it's short.
    293                     if ( strlen( $caption ) < 80 )
     293                    if ( mbstring_binary_safe_strlen( $caption ) < 80 )
    294294                        $meta['title'] = $caption;
    295295                    else
     
    328328
    329329        if ( ! empty( $exif['ImageDescription'] ) ) {
    330             if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) {
     330            if ( empty( $meta['title'] ) && mbstring_binary_safe_strlen( $exif['ImageDescription'] ) < 80 ) {
    331331                // Assume the title is stored in ImageDescription
    332332                $meta['title'] = trim( $exif['ImageDescription'] );
  • trunk/src/wp-includes/formatting.php

    r28802 r28806  
    482482 */
    483483function seems_utf8($str) {
    484     $length = strlen($str);
     484    $length = mbstring_binary_safe_strlen($str);
    485485    for ($i=0; $i < $length; $i++) {
    486486        $c = ord($str[$i]);
     
    706706    $unicode_length = 0;
    707707
    708     $string_length = strlen( $utf8_string );
     708    $string_length = mbstring_binary_safe_strlen( $utf8_string );
    709709    for ($i = 0; $i < $string_length; $i++ ) {
    710710
  • trunk/src/wp-includes/functions.php

    r28794 r28806  
    44064406
    44074407/**
     4408 * Uses a binary-safe encoding to get the length of a string in bytes if func_overload is enabled.
     4409 *
     4410 * @see mbstring_binary_safe_encoding()
     4411 *
     4412 * @since 4.0.0
     4413 *
     4414 * @param string $string The string to get the length of.
     4415 * @return int The length of the string in bytes.
     4416 */
     4417function mbstring_binary_safe_strlen( $string ) {
     4418    mbstring_binary_safe_encoding();
     4419    $length = strlen( $string );
     4420    reset_mbstring_encoding();
     4421
     4422    return $length;
     4423}
     4424
     4425/**
    44084426 * Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN )
    44094427 *
  • trunk/src/wp-includes/pomo/mo.php

    r28472 r28806  
    7676        $originals_table = chr(0);
    7777
     78        $reader = new POMO_Reader();
     79
    7880        foreach($entries as $entry) {
    7981            $originals_table .= $this->export_original($entry) . chr(0);
    80             $length = strlen($this->export_original($entry));
     82            $length = $reader->strlen($this->export_original($entry));
    8183            fwrite($fh, pack('VV', $length, $current_addr));
    8284            $current_addr += $length + 1; // account for the NULL byte after
     
    8486
    8587        $exported_headers = $this->export_headers();
    86         fwrite($fh, pack('VV', strlen($exported_headers), $current_addr));
     88        fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr));
    8789        $current_addr += strlen($exported_headers) + 1;
    8890        $translations_table = $exported_headers . chr(0);
     
    9092        foreach($entries as $entry) {
    9193            $translations_table .= $this->export_translations($entry) . chr(0);
    92             $length = strlen($this->export_translations($entry));
     94            $length = $reader->strlen($this->export_translations($entry));
    9395            fwrite($fh, pack('VV', $length, $current_addr));
    9496            $current_addr += $length + 1;
Note: See TracChangeset for help on using the changeset viewer.