Back button doesn't close MediaViewer if the URL has a fragment with "/"

Bug: T361612
Change-Id: I1a516dbe62bd3a8c621a148c3fb36111128a57ef
This commit is contained in:
Simon Legner 2024-10-13 14:12:58 +02:00
parent fc75d3aabe
commit a12565e8aa
2 changed files with 20 additions and 2 deletions

View file

@ -706,8 +706,8 @@ class MultimediaViewer {
* Sets up the route handlers * Sets up the route handlers
*/ */
setupRouter() { setupRouter() {
// handle empty hashes, and anchor links (page sections) // handle empty hashes, and anchor links (page sections, possibly including /)
this.router.addRoute( /^[^/]*$/, () => { this.router.addRoute( /.*$/, () => {
if ( this.isOpen ) { if ( this.isOpen ) {
comingFromHashChange = true; comingFromHashChange = true;
document.title = this.createDocumentTitle( null ); document.title = this.createDocumentTitle( null );

View file

@ -450,6 +450,24 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
} }
} ); } );
QUnit.test( 'Viewer is closed then navigating to #foo/bar/baz (page section including slash)', function ( assert ) {
location.hash = '#/media/foo';
const viewer = getMultimediaViewer();
viewer.isOpen = true;
viewer.ui = undefined;
this.sandbox.stub( viewer, 'close' );
location.hash = '#foo/bar/baz';
// Wait for route event handler to execute
const done = assert.async();
setTimeout( () => {
assert.true( viewer.close.called, 'The viewer was closed' );
done();
}, 100 );
} );
QUnit.test( 'Refuse to load too-big thumbnails', ( assert ) => { QUnit.test( 'Refuse to load too-big thumbnails', ( assert ) => {
let expectedWidth; let expectedWidth;
const reuestedWidth = 1000; const reuestedWidth = 1000;