mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-03 08:40:10 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38052 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1321,6 +1321,50 @@ EOF;
|
||||
$this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta5 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36549
|
||||
* @ticket 33641
|
||||
*/
|
||||
function test_wp_calculate_image_srcset_with_spaces_in_filenames() {
|
||||
// Mock data for this test.
|
||||
$image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test image-300x150.png';
|
||||
$image_meta = array(
|
||||
'width' => 2000,
|
||||
'height' => 1000,
|
||||
'file' => '2015/12/test image.png',
|
||||
'sizes' => array(
|
||||
'thumbnail' => array(
|
||||
'file' => 'test image-150x150.png',
|
||||
'width' => 150,
|
||||
'height' => 150,
|
||||
'mime-type' => 'image/png',
|
||||
),
|
||||
'medium' => array(
|
||||
'file' => 'test image-300x150.png',
|
||||
'width' => 300,
|
||||
'height' => 150,
|
||||
'mime-type' => 'image/png',
|
||||
),
|
||||
'medium_large' => array(
|
||||
'file' => 'test image-768x384.png',
|
||||
'width' => 768,
|
||||
'height' => 384,
|
||||
'mime-type' => 'image/png',
|
||||
),
|
||||
'large' => array(
|
||||
'file' => 'test image-1024x512.png',
|
||||
'width' => 1024,
|
||||
'height' => 512,
|
||||
'mime-type' => 'image/png',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$expected_srcset = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test%20image-300x150.png 300w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test%20image-768x384.png 768w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test%20image-1024x512.png 1024w';
|
||||
|
||||
$this->assertSame( $expected_srcset, wp_calculate_image_srcset( array( 300, 150 ), $image_src, $image_meta ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33641
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user