From 6ed1cdd43e7a063ce9a668f5623e8dae02fa8d37 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Sun, 18 Feb 2024 08:58:07 +0200 Subject: [PATCH] Selector Engine: fix multiple IDs (#39201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: regression of #38989 * Add unit test in selector-engine.spec.js --------- Co-authored-by: Julien Déramond Co-authored-by: XhmikosR --- js/src/dom/selector-engine.js | 4 ++-- js/tests/unit/dom/selector-engine.spec.js | 12 ++++++++++ js/tests/unit/modal.spec.js | 29 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js index a47f72001bd5..a4d81f3b9127 100644 --- a/js/src/dom/selector-engine.js +++ b/js/src/dom/selector-engine.js @@ -26,10 +26,10 @@ const getSelector = element => { hrefAttribute = `#${hrefAttribute.split('#')[1]}` } - selector = hrefAttribute && hrefAttribute !== '#' ? parseSelector(hrefAttribute.trim()) : null + selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null } - return selector + return selector ? selector.split(',').map(sel => parseSelector(sel)).join(',') : null } const SelectorEngine = { diff --git a/js/tests/unit/dom/selector-engine.spec.js b/js/tests/unit/dom/selector-engine.spec.js index 72c0bf6db86f..95d9bf8ec9d8 100644 --- a/js/tests/unit/dom/selector-engine.spec.js +++ b/js/tests/unit/dom/selector-engine.spec.js @@ -371,6 +371,18 @@ describe('SelectorEngine', () => { expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target'))) }) + it('should get elements if several ids with special chars are given', () => { + fixtureEl.innerHTML = [ + '
', + '
', + '
' + ].join('') + + const testEl = fixtureEl.querySelector('#test') + + expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target'))) + }) + it('should get elements in array, from href if no data-bs-target set', () => { fixtureEl.innerHTML = [ '', diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index b5c03131287e..2aa0b7655c14 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -991,6 +991,35 @@ describe('Modal', () => { trigger.click() }) }) + + it('should open modal, having special characters in its id', () => { + return new Promise(resolve => { + fixtureEl.innerHTML = [ + '', + '' + ].join('') + + const modalEl = fixtureEl.querySelector('.modal') + const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]') + + modalEl.addEventListener('shown.bs.modal', () => { + resolve() + }) + + trigger.click() + }) + }) + it('should not prevent default when a click occurred on data-bs-dismiss="modal" where tagName is DIFFERENT than or ', () => { return new Promise(resolve => { fixtureEl.innerHTML = [