Changeset 60195
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r60084 r60195 156 156 str_starts_with( $files['file']['type'], 'image/' ) 157 157 ) { 158 // Check if the image editor supports the type. 159 if ( ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) ) ) { 158 // List of non-resizable image formats. 159 $editor_non_resizable_formats = array( 160 'image/svg+xml', 161 ); 162 163 // Check if the image editor supports the type or ignore if it isn't a format resizable by an editor. 164 if ( 165 ! in_array( $files['file']['type'], $editor_non_resizable_formats, true ) && 166 ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) ) 167 ) { 160 168 return new WP_Error( 161 169 'rest_upload_image_type_not_supported', -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r60084 r60195 34 34 35 35 /** 36 * @var string The path to the SVG test image. 37 */ 38 private static $test_svg_file; 39 40 /** 36 41 * @var array The recorded posts query clauses. 37 42 */ … … 114 119 if ( ! file_exists( self::$test_avif_file ) ) { 115 120 copy( $orig_avif_file, self::$test_avif_file ); 121 } 122 123 $test_svg_file = DIR_TESTDATA . '/uploads/video-play.svg'; 124 self::$test_svg_file = get_temp_dir() . 'video-play.svg'; 125 if ( ! file_exists( self::$test_svg_file ) ) { 126 copy( $test_svg_file, self::$test_svg_file ); 116 127 } 117 128 … … 2604 2615 $this->assertSame( 201, $response->get_status() ); 2605 2616 } 2617 2618 /** 2619 * Test that uploading an SVG image doesn't throw a `rest_upload_image_type_not_supported` error. 2620 * 2621 * @ticket 63302 2622 */ 2623 public function test_upload_svg_image() { 2624 wp_set_current_user( self::$editor_id ); 2625 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 2626 $request->set_header( 'Content-Type', 'image/svg+xml' ); 2627 $request->set_file_params( 2628 array( 2629 'file' => array( 2630 'file' => file_get_contents( self::$test_svg_file ), 2631 'name' => 'video-play.svg', 2632 'size' => filesize( self::$test_svg_file ), 2633 'tmp_name' => self::$test_svg_file, 2634 'type' => 'image/svg+xml', 2635 ), 2636 ) 2637 ); 2638 $rest_controller = new WP_REST_Attachments_Controller( 'attachment' ); 2639 $result = $rest_controller->create_item_permissions_check( $request ); 2640 2641 $this->assertTrue( $result ); 2642 } 2606 2643 }
Note: See TracChangeset
for help on using the changeset viewer.