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

DOMException is thrown for selectors with an explicit empty attribute value #881

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

DOMException is thrown for selectors with an explicit empty attribute value #881

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

Comments

@romansp
Copy link
Contributor

romansp commented May 1, 2023

Describe the bug
DOMException: Invalid selector is thrown for an empty attribute value selector, e.g. [contenteditable=""] or [disabled=""].

To Reproduce

// throws DOMException: Invalid selector: "[contenteditable=""], [contenteditable="true"]"

it('Returns all elements matching "[contenteditable=""], [contenteditable="true"]".', () => {
	document.body.innerHTML = `
		<div contenteditable></div>
		<div contenteditable=""></div>
		<div contenteditable="true"></div>
		<div contenteditable="false"></div>
	`;
	const elements = document.querySelectorAll('[contenteditable=""], [contenteditable="true"]');
	expect(elements.length).toBe(3);
	expect(elements[0] === document.body.children[0]).toBe(true);
});

Expected behavior
Selector [contenteditable=""] should be considered correct.

Device:

  • Version 9.10.1.

Additional context
This is a regression introduced in v9.10.0.

For reference testing-library/user-event uses this quite complex selector with empty attribute value to find focusable elements on the page: https://github.com/testing-library/user-event/blob/7a305dee9ab833d6f338d567fc2e862b4838b76a/src/utils/focus/selector.ts#L1

@romansp romansp added the bug Something isn't working label May 1, 2023
@capricorn86 capricorn86 self-assigned this May 2, 2023
capricorn86 added a commit that referenced this issue May 2, 2023
capricorn86 added a commit that referenced this issue May 2, 2023
…own-for-selectors-with-an-explicit-empty-attribute-value

#881@patch: Adds support for query selectors for attributes with empt…
@capricorn86
Copy link
Owner

Thank you for reporting @romansp! 🙂

The issue has been fixed:
https://github.com/capricorn86/happy-dom/releases/tag/v9.10.2

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