diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index 5ab3cd1913..0d93649175 100644
--- a/src/wp-includes/media.php
+++ b/src/wp-includes/media.php
@@ -1376,7 +1376,7 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
 		if ( wp_image_matches_ratio( $image_width, $image_height, $image['width'], $image['height'] ) ) {
 			// Add the URL, descriptor, and value to the sources array to be returned.
 			$source = array(
-				'url'        => $image_baseurl . $image['file'],
+				'url'        => $image_baseurl . urlencode( $image['file'] ),
 				'descriptor' => 'w',
 				'value'      => $image['width'],
 			);
@@ -1426,7 +1426,7 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
 	$srcset = '';
 
 	foreach ( $sources as $source ) {
-		$srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', ';
+		$srcset .= $source['url'] . ' ' . $source['value'] . $source['descriptor'] . ', ';
 	}
 
 	return rtrim( $srcset, ', ' );
