From c45cffb41cd0c0d9ec94c6bd22853320b6a5bdac Mon Sep 17 00:00:00 2001 From: Aryan Jasala Date: Thu, 29 Oct 2026 07:28:15 +0530 Subject: [PATCH 1/2] Media: Send array values from the upload pipeline as arrays. When several registered image sizes have the same dimensions, the upload pipeline sideloads one file for all of them and passes their names as an array in `image_size`. `flattenFormData()` in `media-upload-pipeline.js` turned that array into the string `a,b`, so the sideload endpoint rejected it and those sizes were never created. This handles arrays the same way as the `flattenFormData()` in the media-utils package, which was fixed in Gutenberg PR 82353. See #66412. --- src/js/_enqueues/admin/media-upload-pipeline.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/js/_enqueues/admin/media-upload-pipeline.js b/src/js/_enqueues/admin/media-upload-pipeline.js index 58dceae7affcc..eccdaaad94560 100644 --- a/src/js/_enqueues/admin/media-upload-pipeline.js +++ b/src/js/_enqueues/admin/media-upload-pipeline.js @@ -39,7 +39,7 @@ window.wp = window.wp || {}; const imageSizeCount = Object.keys( settings.allImageSizes || {} ).length; /** - * Recursively appends data to a FormData object, supporting nested objects. + * Recursively appends data to a FormData object, supporting nested objects and arrays. * * Mirrors flattenFormData() in the media-utils package. * @@ -49,9 +49,10 @@ window.wp = window.wp || {}; */ function flattenFormData( formData, key, data ) { if ( - data !== null && - typeof data === 'object' && - Object.getPrototypeOf( data ) === Object.prototype + Array.isArray( data ) || + ( data !== null && + typeof data === 'object' && + Object.getPrototypeOf( data ) === Object.prototype ) ) { Object.keys( data ).forEach( function ( name ) { flattenFormData( formData, key + '[' + name + ']', data[ name ] ); From 194ac12c351d027ddd717f51bf26006d1a1d1d23 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 23 Nov 2026 09:34:51 -0800 Subject: [PATCH 2/2] Tests: Cover image sizes that share dimensions in the upload pipeline. The existing client-side upload specs only check the default sizes, so they pass whether or not `flattenFormData()` sends the `image_size` array correctly, and the copy in core could lose its array handling again unnoticed. Register two sizes with the same dimensions through a must-use plugin and assert that every sideload succeeds and both sizes are created. The plugin only acts on requests carrying this test's cookie, so other tests sharing the site are unaffected. See #66412. Claude-Session: https://claude.ai/code/session_018vwYjUKQHg7Dn2Lj1vTwmX --- .../media-new-client-side-upload.test.js | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/e2e/specs/media-new-client-side-upload.test.js b/tests/e2e/specs/media-new-client-side-upload.test.js index 65e731654a1c9..39b943fb554a0 100644 --- a/tests/e2e/specs/media-new-client-side-upload.test.js +++ b/tests/e2e/specs/media-new-client-side-upload.test.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { randomUUID } from 'node:crypto'; + /** * Internal dependencies */ @@ -166,6 +171,70 @@ test.describe( 'Add New Media File client-side uploads', () => { expect( thumbnailResponse.status() ).toBe( 200 ); } ); + test( 'creates every image size when two sizes share dimensions', async ( { + page, + admin, + attachments, + requestUtils, + muPlugin, + baseURL, + } ) => { + // Sizes with the same dimensions are sideloaded as one file, with + // their names sent as an array in `image_size`. Other workers share + // the site, so only this test's requests see the extra sizes. + const trigger = `e2e_${ randomUUID().replaceAll( '-', '' ) }`; + await muPlugin.write( + 'shared-image-sizes.php', + ` { + if ( + /\/wp\/v2\/media\/\d+\/sideload/.test( + decodeURIComponent( response.url() ) + ) + ) { + sideloadStatuses.push( response.status() ); + } + } ); + + const ids = trackUploads( page, attachments ); + const fileInput = page.locator( FILE_INPUT_SELECTOR ).first(); + await expect( fileInput ).toBeAttached( { timeout: 30_000 } ); + await fileInput.setInputFiles( TEST_IMAGE_PATH ); + + await expect( editLinks( page ) ).toBeVisible( { timeout: 60_000 } ); + + expect( sideloadStatuses.length ).toBeGreaterThanOrEqual( 1 ); + expect( + sideloadStatuses.filter( ( status ) => status !== 200 ) + ).toEqual( [] ); + + const attachment = await requestUtils.rest( { + path: `/wp/v2/media/${ ids.at( -1 ) }`, + } ); + expect( Object.keys( attachment.media_details.sizes || {} ) ).toEqual( + expect.arrayContaining( [ 'e2e-shared-a', 'e2e-shared-b' ] ) + ); + } ); + test( 'warns before leaving while a pipeline upload is in flight', async ( { page, admin,