Make WordPress Core


Ignore:
Timestamp:
07/13/2016 03:23:27 PM (8 years ago)
Author:
joemcgill
Message:

Media: URL encode spaces in srcset attributes.

In some cases, images in the media library may contain spaces in
their filenames. This results in an invalid srcset attribute,
causing broken images on the front end. This change fixes the issue
by replacing spaces in URLs with URL encoded '%20' characters before
returning the srcset string.

Props underdude, joemcgill.
Fixes #36549.

File:
1 edited

Legend:

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

    r38012 r38052  
    11431143     * @param string $image_src     The 'src' of the image.
    11441144     * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    1145      * @param int    $attachment_id Image attachment ID or 0.
     1145     * @param int    $attachment_id Image attachment ID or 0.
    11461146     */
    11471147    $sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );
     
    11551155
    11561156    foreach ( $sources as $source ) {
    1157         $srcset .= $source['url'] . ' ' . $source['value'] . $source['descriptor'] . ', ';
     1157        $srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', ';
    11581158    }
    11591159
Note: See TracChangeset for help on using the changeset viewer.