Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils.getFlattenTree): default to documentElement #2260

Merged
merged 1 commit into from
Jun 5, 2020

Conversation

straker
Copy link
Contributor

@straker straker commented Jun 3, 2020

In investigating various things, we discovered that passing in a subtree of the DOM to getFlattenTree would give bad results when running various APIs. For example, trying to get the accessible name of this structure would return '' and running the label rule would fail:

<div id="foo">lablled</div>
<input  id="context" aria-labelledby="foo">

<script>
var input = document.getElementById('context');
axe.utils.getFlattenTree(document.getElementById('context'));
var a11yName = axe.utils.accessibleText(input);
assert('a11yName === 'foo');  // returns false
</script>

This doesn't happen in a normal axe.run as we always set up the virtual tree to be the documentElement regardless of what node is passed in. This is only an issue with getFlattenTree.

getFlattenTree expects a node to be passed in, but we only can get correct results if documentElement or body is passed in. If any other node is passed in we cannot guarantee correct results. Looking through github for uses, it seems most users are passing in documentElement, but there are some uses of non-documentElement that would cause problems.

To remedy this and not introduce a breaking change, I made passing in a node optional and instead have the code default to documentElement. I also added a note to the docs to warn users of problems passing in a node that is not body or documentElement.

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Code is reviewed for security

@straker straker requested a review from a team as a code owner June 3, 2020 15:12
@straker straker merged commit 8b14ccc into develop Jun 5, 2020
@straker straker deleted the flatten-tree branch June 5, 2020 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants