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

Selector attribute modifiers ~ and | doesn't match valid elements #914

Closed
romansp opened this issue May 12, 2023 · 1 comment · Fixed by #919
Closed

Selector attribute modifiers ~ and | doesn't match valid elements #914

romansp opened this issue May 12, 2023 · 1 comment · Fixed by #919
Assignees
Labels
bug Something isn't working

Comments

@romansp
Copy link
Contributor

romansp commented May 12, 2023

Describe the bug
Modifiers ~ and | doesn't match valid elements when attribute doesn't have whitespace or dash.

To Reproduce
The following test will currently fail because none of elements will be matched.

it('Returns all elements matching "*[role~="menu"]".', () => {
  const container = document.createElement('div');
  container.innerHTML = '<div role="menu">Menu</div>';
  const elements = container.querySelectorAll('*[role~="menu"]');
  
  expect(elements.length).toBe(1);
});

Expected behavior
Selector *[role~="menu"] should match element with "role=menu"

Device:

  • Version 9.17.0

Additional context
Introduced by changes in #913.

Interesting that this regression wasn't caught by [class~="class2"] test because elements in QuerySelectorHTML have space, e.g. class="class1 class2"

@romansp romansp added the bug Something isn't working label May 12, 2023
@capricorn86 capricorn86 self-assigned this May 13, 2023
capricorn86 added a commit that referenced this issue May 13, 2023
…"|" as operators for finding attributes containing a word did not match when there was only one word.
capricorn86 added a commit that referenced this issue May 13, 2023
…iers-doesnt-match-valid-elements

#914@patch: Fixes issue where attribute query selectors using "~" or …
@capricorn86
Copy link
Owner

Thank you for reporting @romansp! 🙂

I have made a fix and also added some unit tests that should cover it now 😅

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.18.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants