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.
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.
Describe the bug If selector that starts with a new line, Happy DOM throws an error "Invalid selector".
To Reproduce I forked the happy-dom repro and added a test in
QuerySelector.test.ts
. Clone the repro, switch to thebug/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
Expected behavior The selector should work because it's valid and works in the browser.
Device:
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.