cssnano icon indicating copy to clipboard operation
cssnano copied to clipboard

[Bug]: Cssnano hangs when including `|` character in identifier

Open mattcoley opened this issue 3 years ago • 2 comments

Describe the bug

Including | at the beginning of a CSS selector results in the cssnano process never terminating. For example minification of:

| h1 {}

does not terminate.

Other combinations of selectors with this character work fine: h1 |, |h1, h1|.

Output from postcss parse:

Root {
  raws: { semicolon: false, after: '' },
  type: 'root',
  nodes: [
    Rule {
      raws: [Object],
      type: 'rule',
      nodes: [Array],
      parent: [Circular *1],
      source: [Object],
      selector: '| body',
      [Symbol(isClean)]: false,
      [Symbol(my)]: true
    }
  ],
  source: {
    input: Input {
      css: '| body { margin:0; }',
      hasBOM: false,
      id: '<input css -2Oudu>',
      [Symbol(fromOffsetCache)]: [Array]
    },
    start: { offset: 0, line: 1, column: 1 }
  },
  [Symbol(isClean)]: false,
  [Symbol(my)]: true
}

Expected behaviour

cssnano should exit on this input.

Steps to reproduce

Problem can be validated via https://cssnano.co/playground/

For cli usage:

postcss test.css --use cssnano --no-map

Version

5.1.11

Preset

(no preset)

Environment

System:
    OS: macOS 11.6.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 50.88 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh

Package details

└── [email protected]

Additional context

No response

mattcoley avatar Jun 14 '22 15:06 mattcoley

Including | at the beginning of a CSS selector results in the cssnano process never terminating

Why would the stylesheet include a | at the start of a selector? Is it not invalid CSS?

ludofischer avatar Jun 16 '22 21:06 ludofischer

It is invalid CSS (in this case accidental) but the process should still terminate. We came across this bug in our CI/CD pipeline where the builds would timeout rather than fail and display an error message (invalid CSS). Other examples of invalid CSS terminate with an error message.

mattcoley avatar Jun 21 '22 20:06 mattcoley