Skip to content

Incorrect comment handling in some edge-case #175

Closed

Description

@holblin

Expected Behaviour

Comments are properly ignored in all places.

Actual Behaviour

Comment in the selector that contains a { break the parsing because the { evaluation is done before the comment escaping.

Steps to Reproduce

  • Change the file test/cases/comment/input.css by:
/* 1 */

head, /* footer, */body/*, nav */ { /* 2 */
  /* 3 */
  /**/foo: 'bar';
  /* 4 */
} /* 5 */

/* 6 */
  • Run yarn test

Logs taken while reproducing the problem

$jest
 PASS  test/parse.test.ts
 FAIL  test/cases.test.ts
  ● cases/comment › should match ast.json

    input.css:3:37: property missing ':'

      77 |
      78 |   function error(msg: string) {
    > 79 |     const err = new CssParseError(
         |                 ^
      80 |       options?.source || '',
      81 |       msg,
      82 |       lineno,

      at error (src/parse/index.ts:79:17)
      at declaration (src/parse/index.ts:263:14)
      at declarations (src/parse/index.ts:294:20)
      at rule (src/parse/index.ts:716:21)
      at rules (src/parse/index.ts:134:71)
      at stylesheet (src/parse/index.ts:98:23)
      at parse (src/parse/index.ts:720:20)
      at parseInput (test/cases.test.ts:39:19)
      at Object.<anonymous> (test/cases.test.ts:15:19)

Potential fix

  • Add a special condition in the regex for the selector to skip the comments. This should not reduce performance or introduce a dos vulnerability.
  • Change the parsing to skip the comment while doing the parsing.

Activity

  1. jogibear9988 commented on Mar 17, 2026

    @jogibear9988

    should be fixed in #621

  2. jogibear9988 commented on May 20, 2026

    @jogibear9988

    fixed

  3. holblin commented on May 20, 2026

    @holblin
    Author

    Fixed in Release 4.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions