Make WordPress Core

Ticket #18412: 18412.diff

File 18412.diff, 1.5 KB (added by kurtpayne, 13 years ago)

Patch to fix %XX in media filenames

  • wp-includes/post.php

     
    39133913        if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this.
    39143914                $url = get_the_guid( $post->ID );
    39153915
    3916         $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
     3916        $url = apply_filters( 'wp_get_attachment_url', wp_double_encode_url($url), $post->ID );
    39173917
    39183918        if ( 'attachment' != $post->post_type || empty( $url ) )
    39193919                return false;
     
    39223922}
    39233923
    39243924/**
     3925 * Double encode any accidental %XX combinations in the filename (e.g. "My%20Picture.jpg")
     3926 * @param string $url
     3927 * @return string
     3928 */
     3929function wp_double_encode_url($url) {
     3930        return preg_replace('/%\d\d/e', "rawurlencode(rawurlencode(urldecode('$0')))", $url);
     3931}
     3932
     3933/**
    39253934 * Retrieve thumbnail for an attachment.
    39263935 *
    39273936 * @since 2.1.0
  • wp-includes/media.php

     
    169169                // we have the actual image size, but might need to further constrain it if content_width is narrower
    170170                list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
    171171
    172                 return array( $img_url, $width, $height, $is_intermediate );
     172                return array( wp_double_encode_url($img_url), $width, $height, $is_intermediate );
    173173        }
    174174        return false;
    175175