From a12565e8aa0e3dea24fdcd71e83e8b8c68fc8d0e Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sun, 13 Oct 2024 14:12:58 +0200 Subject: [PATCH] Back button doesn't close MediaViewer if the URL has a fragment with "/" Bug: T361612 Change-Id: I1a516dbe62bd3a8c621a148c3fb36111128a57ef --- resources/mmv/mmv.js | 4 ++-- tests/qunit/mmv/mmv.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 9161d6a7b..21a2cf889 100644 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -706,8 +706,8 @@ class MultimediaViewer { * Sets up the route handlers */ setupRouter() { - // handle empty hashes, and anchor links (page sections) - this.router.addRoute( /^[^/]*$/, () => { + // handle empty hashes, and anchor links (page sections, possibly including /) + this.router.addRoute( /.*$/, () => { if ( this.isOpen ) { comingFromHashChange = true; document.title = this.createDocumentTitle( null ); diff --git a/tests/qunit/mmv/mmv.test.js b/tests/qunit/mmv/mmv.test.js index cae442e49..11d77e3b2 100644 --- a/tests/qunit/mmv/mmv.test.js +++ b/tests/qunit/mmv/mmv.test.js @@ -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 ) => { let expectedWidth; const reuestedWidth = 1000;