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

CSS comment with asterisk gets parsed as part of selectorText #887

Closed
htuomola opened this issue May 3, 2023 · 1 comment
Closed

CSS comment with asterisk gets parsed as part of selectorText #887

htuomola opened this issue May 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@htuomola
Copy link

htuomola commented May 3, 2023

Describe the bug
If CSS comment contains * character in the middle, the comment is not omitted and ends up being parsed as part of selectorText.
This, of course, makes selectorText invalid for later use.

To Reproduce
Steps to reproduce the behavior:

  1. Add following CSS:
/*
* Some comment here 
*/
.foo { color: red; }
  1. Run happy-dom (well, running vitest with happy-dom)
  2. Run fails with error similar to
DOMException: Invalid selector: "/*
* Some comment here 
*/
.foo"
 ❯ Function.getSelectorGroups node_modules/happy-dom/src/query-selector/SelectorParser.ts:143:10
 ❯ Function.match node_modules/happy-dom/src/query-selector/QuerySelector.ts:100:38
 ❯ CSSStyleDeclarationElementStyle.parseCSSRules node_modules/happy-dom/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts:292:42
 ❯ CSSStyleDeclarationElementStyle.getComputedElementStyle node_modules/happy-dom/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts:124:12
 ❯ CSSStyleDeclarationElementStyle.getElementStyle node_modules/happy-dom/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts:59:16
 ❯ CSSStyleDeclaration.getPropertyValue node_modules/happy-dom/src/css/declaration/AbstractCSSStyleDeclaration.ts:193:37

Expected behavior
CSS is parsed correctly and commit is omitted.

** Analysis **
It's just a problem with CSSParser regex used for comments.
I have a test and a fix for CssParser ready and fill submit PR soon.

@htuomola htuomola added the bug Something isn't working label May 3, 2023
htuomola pushed a commit to htuomola/happy-dom that referenced this issue May 3, 2023
htuomola pushed a commit to htuomola/happy-dom that referenced this issue May 3, 2023
htuomola pushed a commit to htuomola/happy-dom that referenced this issue May 3, 2023
htuomola pushed a commit to htuomola/happy-dom that referenced this issue May 3, 2023
capricorn86 added a commit that referenced this issue May 3, 2023
#887@patch: Fix parsing CSS comments with asterisks.
@capricorn86
Copy link
Owner

@htuomola your fix has been released 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.10.7

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

2 participants