Skip to content

Commit

Permalink
Merge pull request #1212 from btea/task/0-update-match-invalid-select…
Browse files Browse the repository at this point in the history
…or-regexp

#0@patch: Update the regularity of the invalid selector.
  • Loading branch information
capricorn86 authored Feb 25, 2024
2 parents f522225 + 50976ce commit b98ae50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/query-selector/QuerySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type IDocumentPositionAndElement = {
/**
* Invalid Selector RegExp.
*/
const INVALID_SELECTOR_REGEXP = /^[.#\[]?\d/;
const INVALID_SELECTOR_REGEXP = /^[.#\[]?\d|[.#]$/;

/**
* Utility for query selection in an HTML element.
Expand Down
12 changes: 12 additions & 0 deletions packages/happy-dom/test/query-selector/QuerySelector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,12 @@ describe('QuerySelector', () => {
expect(() => div.querySelectorAll('#1')).toThrowError(
"Failed to execute 'querySelectorAll' on 'HTMLElement': '#1' is not a valid selector."
);
expect(() => div.querySelectorAll('a.')).toThrowError(
"Failed to execute 'querySelectorAll' on 'HTMLElement': 'a.' is not a valid selector."
);
expect(() => div.querySelectorAll('a#')).toThrowError(
"Failed to execute 'querySelectorAll' on 'HTMLElement': 'a#' is not a valid selector."
);
});
});

Expand Down Expand Up @@ -1178,6 +1184,12 @@ describe('QuerySelector', () => {
expect(() => div.querySelector('#1')).toThrowError(
"Failed to execute 'querySelector' on 'HTMLElement': '#1' is not a valid selector."
);
expect(() => div.querySelector('a.')).toThrowError(
"Failed to execute 'querySelector' on 'HTMLElement': 'a.' is not a valid selector."
);
expect(() => div.querySelector('a#')).toThrowError(
"Failed to execute 'querySelector' on 'HTMLElement': 'a#' is not a valid selector."
);
});

it('Has support for passing pseudoseletors inside :not', () => {
Expand Down

0 comments on commit b98ae50

Please sign in to comment.