Skip to content

Commit

Permalink
fix: [capricorn86#1414] Normalize selector parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
syi0808 committed Jul 27, 2024
1 parent e6f9127 commit c6f4c85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/happy-dom/src/query-selector/SelectorParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export default class SelectorParser {
selector: string,
options?: { ignoreErrors?: boolean }
): Array<Array<SelectorItem>> {
selector = selector.replace(/[\n\r\f\t]/g, '').trim();

const ignoreErrors = options?.ignoreErrors;
if (selector === '*') {
return [[new SelectorItem({ tagName: '*', ignoreErrors })]];
Expand Down
10 changes: 10 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,16 @@ describe('QuerySelector', () => {
expect(container.querySelector(':where(div)')).toBe(container.children[0]);
expect(container.querySelector(':where(span[attr1="val,ue1"])')).toBe(null);
});

it('Remove new line from selector and trim selector before parse', () => {
const container = document.createElement('div');

container.innerHTML = QuerySelectorHTML;

expect(container.querySelector('\n \n\r \t \f h1 \n \n\r \t \f')).toBe(
container.children[0].children[0]
);
});
});

describe('matches()', () => {
Expand Down

0 comments on commit c6f4c85

Please sign in to comment.