capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.24k stars 194 forks source link

CSS escaped attribute name selectors throws invalid selector error #1031

Open koculu opened 1 year ago

koculu commented 1 year ago

Describe the bug CSS escaped attribute name selectors throws invalid selector error. attribute names starting with ':' is very common and it should be escaped to '\:' in queries.

To Reproduce execute the following query document.querySelectorAll('[\\:src]')

throws an error: DOMException: Invalid selector: "[\:src]"

Expected behavior CSS escaped attribute name selectors should work with no errors.

koculu commented 1 year ago

Issue seems related with CSS.escape project. The author of CSS.escape says: "For a more powerful alternative, consider using cssesc, which automatically takes care of excessive whitespace, and has many options to customize the output."

I haven't tested yet but it might be quick fix by switching the dependency to the following project: https://github.com/mathiasbynens/cssesc

koculu commented 1 year ago

Created following issue on the CSS.escape project. https://github.com/mathiasbynens/CSS.escape/issues/17 and https://github.com/mathiasbynens/cssesc/issues/31 on the cssesc project. Both of them fail with ':' character.

tamascsaba commented 1 month ago

I have a similar issue, I use happy-dom to test my angularjs application, but I got the following error.

DOMException: Invalid selector: "[ng\:jq]"