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

Robustness : fix a case where tokenizer state is broken #1001

Closed
abarre opened this issue Feb 6, 2018 · 3 comments
Closed

Robustness : fix a case where tokenizer state is broken #1001

abarre opened this issue Feb 6, 2018 · 3 comments

Comments

@abarre
Copy link
Contributor

abarre commented Feb 6, 2018

Our solution minifies CSS from various websites and some CSS have "corrupted CSS portion". One case completely breaks the tokenizer state and destroy all URL in the CSS file.

If a corrupted CSS portion contains a ), the variable roundBracketLevel will be -1. Then, all URL in the rest of the file won't be correctly parsed and will be deleted.

The patch I found is adding a line that states that roundBracketLevel is always a positive integer in the for loop that parse the CSS code :

roundBracketLevel = Math.max(roundBracketLevel, 0);

Environment

  • clean-css version - npm ls clean-css: clean-css@4.1.9
  • node.js version - node -v: v8.9.4
  • operating system: Mac OS

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS({
level: { 1: {all:false}}
})

Input CSS

.a{background-image:url('bg-buttonh.png'); }
'/imagerie/booking/common/bg-buttonh.png');}
.c{background:url(/carte-bienvenue/bg.jpg)}
.e{background:url(/carte-bienvenue/bg2.jpg)}

Actual output CSS

a{background-image:url(bg-buttonh.png)}'/imagerie/booking/common/bg-buttonh.png')}.c{}.e{}

Expected output CSS

a{background-image:url(bg-buttonh.png)}'/imagerie/booking/common/bg-buttonh.png')}.c{background:url(/carte-bienvenue/bg.jpg)}.e{background:url(/carte-bienvenue/bg2.jpg)}
@jakubpawlowicz
Copy link
Collaborator

Hey @abarre. Thanks for coming back to report the issue - your solution seems right and straightforward to implement. Would you send a PR?

abarre added a commit to abarre/clean-css that referenced this issue Feb 25, 2018
- case of roundBracketLevel inferior to 0.
jakubpawlowicz pushed a commit that referenced this issue Mar 5, 2018
- case of roundBracketLevel inferior to 0.
jakubpawlowicz pushed a commit that referenced this issue Mar 5, 2018
- case of roundBracketLevel inferior to 0.
@jakubpawlowicz
Copy link
Collaborator

Thanks @abarre - I've merged it to master and 4.1 due in 4.1.10 soon.

@jakubpawlowicz
Copy link
Collaborator

Fixed in 4.1.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants