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

Open
rothsandro opened this issue Apr 22, 2024 · 0 comments
Open

Selector starting with new line throws error #1414

rothsandro opened this issue Apr 22, 2024 · 0 comments
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
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

No branches or pull requests

1 participant