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 starting with new line throws error #1414

Closed
rothsandro opened this issue Apr 22, 2024 · 1 comment · Fixed by #1499
Closed

Selector starting with new line throws error #1414

rothsandro opened this issue Apr 22, 2024 · 1 comment · Fixed by #1499
Labels
bug Something isn't working

Comments

@rothsandro
Copy link

Describe the bug
If selector that starts with a new line, Happy DOM throws an error "Invalid selector".

test("selector", () => {
  document.querySelector("\ninput");
});

To Reproduce
I forked the happy-dom repro and added a test in QuerySelector.test.ts.
Clone the repro, switch to the bug/selector-with-new-line branch and run the tests.

Repro: https://github.com/rothsandro/happy-dom/tree/bug/selector-with-new-line

Test: https://github.com/rothsandro/happy-dom/blob/bug/selector-with-new-line/packages/happy-dom/test/query-selector/QuerySelector.test.ts#L1090-L1098

it('Returns an element when selector starts with a new line', () => {
  const div = document.createElement('div');
  const div2 = document.createElement('div');

  div2.className = 'baz';
  div.appendChild(div2);

  expect(div.querySelector('\n.baz') === div2).toBe(true);
});

Expected behavior
The selector should work because it's valid and works in the browser.

Device:

  • OS: Windows 11

Additional context
A third-party component library that we use in our application uses such a selector. Because of that we cannot test parts of our app because it would result in this error.

@rothsandro rothsandro added the bug Something isn't working label Apr 22, 2024
syi0808 added a commit to syi0808/happy-dom that referenced this issue Jul 27, 2024
syi0808 added a commit to syi0808/happy-dom that referenced this issue Jul 28, 2024
capricorn86 added a commit to syi0808/happy-dom that referenced this issue Aug 29, 2024
capricorn86 added a commit that referenced this issue Aug 29, 2024
…space character in CSS selectors (#1499)

* fix: [#1414] Normalize selector parameter

* fix: [#1414] Add more test case

* chore: [#1414] Improves the logic for supporting additional white-space characters in selectors

---------

Co-authored-by: David Ortner <david@ortner.se>
@capricorn86
Copy link
Owner

Thank you for reporting @rothsandro! 🙂

Big thanks to @syi0808 for providing with a fix!

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