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 = [