From c10892b41d0e4de0f19655f4ab9ec1120096a858 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Mon, 18 Sep 2023 01:30:29 +0300 Subject: [PATCH 1/4] fix: regression of #38989 --- js/src/dom/selector-engine.js | 6 +++--- js/tests/unit/modal.spec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js index a47f72001bd5..013971c255ed 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.split(',').map(sel=>parseSelector(sel)).join(',') } const SelectorEngine = { diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index b5c03131287e..34891cb67b14 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -991,6 +991,36 @@ 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 = [ From 7f307fc686d96f42196709633dfb6eba4edf40e0 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Mon, 18 Sep 2023 01:46:15 +0300 Subject: [PATCH 2/4] lint --- js/src/dom/selector-engine.js | 4 ++-- js/tests/unit/modal.spec.js | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js index 013971c255ed..c21f777f06e7 100644 --- a/js/src/dom/selector-engine.js +++ b/js/src/dom/selector-engine.js @@ -28,8 +28,8 @@ const getSelector = element => { selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null } - - return selector.split(',').map(sel=>parseSelector(sel)).join(',') + + return selector?.split(',').map(sel => parseSelector(sel)).join(',') } const SelectorEngine = { diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index 34891cb67b14..2aa0b7655c14 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -995,24 +995,23 @@ describe('Modal', () => { 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() }) From bf2afdf274a37347a73da06f9f5a88519fb317a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20D=C3=A9ramond?= Date: Thu, 5 Oct 2023 11:42:54 +0200 Subject: [PATCH 3/4] Add unit test in selector-engine.spec.js --- js/tests/unit/dom/selector-engine.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 = [ '
', From 13c451b50bbd4cb1633c13a761cf0aade01a439b Mon Sep 17 00:00:00 2001 From: GeoSot Date: Tue, 13 Feb 2024 23:15:39 +0200 Subject: [PATCH 4/4] Update selector-engine.js --- js/src/dom/selector-engine.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js index c21f777f06e7..a4d81f3b9127 100644 --- a/js/src/dom/selector-engine.js +++ b/js/src/dom/selector-engine.js @@ -29,7 +29,7 @@ const getSelector = element => { selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null } - return selector?.split(',').map(sel => parseSelector(sel)).join(',') + return selector ? selector.split(',').map(sel => parseSelector(sel)).join(',') : null } const SelectorEngine = {