Changeset 37002
- Timestamp:
- 03/16/2016 02:17:19 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r36887 r37002 986 986 $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 987 987 988 if ( empty( $image_meta['sizes'] ) ) {988 if ( empty( $image_meta['sizes'] ) || strlen( $image_meta['file'] ) < 4 ) { 989 989 return false; 990 990 } … … 1060 1060 */ 1061 1061 foreach ( $image_sizes as $image ) { 1062 1063 // Check if image meta isn't corrupted. 1064 if ( ! is_array( $image ) ) { 1065 continue; 1066 } 1062 1067 1063 1068 // If the file name is part of the `src`, we've confirmed a match. -
trunk/tests/phpunit/tests/media.php
r36565 r37002 1130 1130 1131 1131 /** 1132 * @ticket 35480 1133 */ 1134 function test_wp_calculate_image_srcset_corrupted_image_meta() { 1135 $size_array = array( 300, 150 ); 1136 $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png'; 1137 $image_meta = array( 1138 'width' => 1600, 1139 'height' => 800, 1140 'file' => '2015/12/test.png', 1141 'sizes' => array( 1142 'thumbnail' => array( 1143 'file' => 'test-150x150.png', 1144 'width' => 150, 1145 'height' => 150, 1146 'mime-type' => 'image/png', 1147 ), 1148 'medium' => array( 1149 'file' => 'test-300x150.png', 1150 'width' => 300, 1151 'height' => 150, 1152 'mime-type' => 'image/png', 1153 ), 1154 'medium_large' => array( 1155 'file' => 'test-768x384.png', 1156 'width' => 768, 1157 'height' => 384, 1158 'mime-type' => 'image/png', 1159 ), 1160 'large' => array( 1161 'file' => 'test-1024x512.png', 1162 'width' => 1024, 1163 'height' => 512, 1164 'mime-type' => 'image/png', 1165 ), 1166 ), 1167 ); 1168 1169 $srcset = array( 1170 300 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w', 1171 768 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w', 1172 1024 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w', 1173 1600 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 1600w', 1174 ); 1175 1176 // No sizes array 1177 $image_meta1 = $image_meta; 1178 unset( $image_meta1['sizes'] ); 1179 $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta1 ) ); 1180 1181 // Sizes is string instead of array; only full size available means no srcset. 1182 $image_meta2 = $image_meta; 1183 $image_meta2['sizes'] = ''; 1184 $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) ); 1185 1186 // File name is incorrect 1187 $image_meta4 = $image_meta; 1188 $image_meta4['file'] = '/'; 1189 $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) ); 1190 1191 // Intermediate size is string instead of array. 1192 $image_meta3 = $image_meta; 1193 $image_meta3['sizes']['medium_large'] = ''; 1194 unset( $srcset[768] ); 1195 $expected_srcset = implode( ', ', $srcset ); 1196 $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) ); 1197 } 1198 1199 /** 1132 1200 * @ticket 33641 1133 1201 */
Note: See TracChangeset
for help on using the changeset viewer.