-
Notifications
You must be signed in to change notification settings - Fork 881
element.cloneNode can cause problems with custom elements #4996
Copy link
Copy link
Closed
Labels
coreIssues in the core code (lib/core)Issues in the core code (lib/core)criticalCritical priorityCritical priorityfixBug fixesBug fixessupport
Milestone
Description
Axe-core uses element.cloneNode in a couple places. Essentially for two reasons:
- to get the element's HTML without its content a shallow clone is used
- To get the attributes where element.attributes is set for silly reasons
<input name=attribute>
Calling element.cloneNode can invoke the constructor of custom elements. I don't think for scenario 2 that's avoidable, but for scenario 1 it is. Instead of cloning, we can do the following:
elmOnlyHtml = elm.outerHTML.replace(elm.innerHTML, '')UPDATE
The solve here is just to rewrite truncateElement to in a way that doesn't require cloneNode. I would also refactor the code. This getSource code should be its own function with its own tests. It'd be nice to make the params configurable. This is a nice function to have:
axe.utils.getSource(elm, { maxLength: 300, attrLimit: 20 })
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreIssues in the core code (lib/core)Issues in the core code (lib/core)criticalCritical priorityCritical priorityfixBug fixesBug fixessupport