BlessCSS / bless

CSS Post-Processor
blesscss.com
MIT License
282 stars 60 forks source link

Bless parsing error with brackets in block comments #24

Open aholmes opened 10 years ago

aholmes commented 10 years ago

This appears to be the same issue as #15.

When processing a CSS file with commented CSS rules (or any block comment containing brackets, the output is rendered incorrectly.

Input CSS:

    /*==ALPHA==*/
    @media (min-width: 1740px) {
        body {
            background-color:red;
        }
    }
    /*==BRAVO==*/
    @media (max-width: 1522px) {
        body {
            /*{}*/
            background-color:blue;
        }
    }
    /*==CHARLIE==*/
    @media (max-width: 1305px) {
        body {
            background-color:yellow;
        }
    }

Output CSS:

    /*==ALPHA==*/
    @media (min-width: 1740px) {
        body {
            background-color:red;
        }
    }
        body {
            /*{}*/
            background-color:blue;
        }
    }
    /*==CHARLIE==*/
    @media (max-width: 1305px) {
        body {
            background-color:yellow;
        }
    }

Notice that BRAVO and the immediately proceeding media query are missing.

Expected output CSS is exactly the same as the Input CSS.

$ blessc -v blessc 3.0.2 (CSS Post-Processor) [JavaScript]

$ node -v v0.10.7

OSX 10.8.4.

betabong commented 10 years ago

Something that goes into the same direction:

  @media (max-width: 750px) {
    html, body {
      width: 100%;
    }
    /*
        .csstransforms3d {
            html, body {
            }
        }
      */
  }

is compiled to:

  html, body {
    width: 100%;
  }
  /*
    .csstransforms3d {
        html, body {
        }
    }
AdamBoman commented 10 years ago

Any progress on this issue? At a glance, it appears to be a problem in the regular expression:

rules = str.match(/([^\{]+\{(?:[^\{\}]|\{[^\{\}]*\})*\})/g),
paulyoung commented 10 years ago

No progress as of yet other than on the 4.0.0-development branch.

Contributions are welcome.

t22james commented 9 years ago

Encountered this error too. Was very sporadic in when it would and would not remove comments, which unfortunately sometimes lead to commented out blocks of code being partially commented back in etc...

As an interim solution, we are now minifying our stylesheet BEFORE passing to bless, thus comments are never actually encountered/messed with by bless...