aem-core-wcm-components
aem-core-wcm-components copied to clipboard
[Accordion v1] Breaking the javascript execution when there is a hash in the URL starting with a number, like #3
Bug Report
Current Behavior
When you have a hash in the URL starting with a number like that your/page/path/index.html#3
the Accordion clientlib just throw an error that breaks the Javascript execution.
Error: Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#3' is not a valid selector.
This error is triggered because the Accordion script tries to select an element based on the hash from URL whithout check if the selector is a valid one and in this case, any css selector starting with a number is not valid for the document.querySelector
method.
Impact Every site that uses the Accordion core component and has its clientlib imported will have this problem.
Expected behavior/code Do not break the code
Environment
- AEM version and patch level - Adobe Experience Manager (6.5.8.0)
- Core Components version 2.18.0
- Java "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
Possible Solution
Additional context / Screenshots
Line of the code that is causing the error https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/accordion/v1/accordion/clientlibs/site/js/accordion.js#L510