From 99c4a1e1f7e0cc5334c66dfd5fa2dc5fa5a9e59d Mon Sep 17 00:00:00 2001 From: Rashed Hossain Date: Tue, 13 Oct 2026 16:30:00 +0600 Subject: [PATCH] Media: Parse only the search term in media grid router when extra query parameters are present When navigating in the Media Library grid view (upload.php), the Backbone router matches `upload.php?search=:query`. If additional query parameters are present after `search=` (for instance `upload.php?search=sunset&mode=grid`), the router's `:query` capture group includes the rest of the query string including the ampersand and additional keys and values. This caused the search input field to be populated with the entire remainder of the query string rather than just the search term. This updates `Router.prototype.search()` to isolate the search term before any `&` parameter delimiter. It also ensures `Router.prototype.showItem()` uses the parsed integer attachment ID when querying `wp.media.attachment()`. Props wprashed. Fixes #65806. --- src/js/media/routers/manage.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/media/routers/manage.js b/src/js/media/routers/manage.js index aabda330aeffa..a659c2ac8f4dd 100644 --- a/src/js/media/routers/manage.js +++ b/src/js/media/routers/manage.js @@ -31,6 +31,9 @@ var Router = Backbone.Router.extend(/** @lends wp.media.view.MediaFrame.Manage.R // Respond to the search route by filling the search field and triggering the input event. search: function( query ) { + if ( query ) { + query = query.split( '&' )[0]; + } jQuery( '#media-search-input' ).val( query ).trigger( 'input' ); }, @@ -39,16 +42,17 @@ var Router = Backbone.Router.extend(/** @lends wp.media.view.MediaFrame.Manage.R var media = wp.media, frame = media.frames.browse, library = frame.state().get('library'), + itemId = parseInt( query, 10 ), item; // Trigger the media frame to open the correct item. - item = library.findWhere( { id: parseInt( query, 10 ) } ); + item = library.findWhere( { id: itemId } ); if ( item ) { item.set( 'skipHistory', true ); frame.trigger( 'edit:attachment', item ); } else { - item = media.attachment( query ); + item = media.attachment( itemId ); frame.listenTo( item, 'change', function( model ) { frame.stopListening( item ); frame.trigger( 'edit:attachment', model );