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

YUI Compressor is breaking some CSS, specifically calc(100% + ##px) #59

Closed
djgilcrease opened this issue Mar 29, 2013 · 78 comments
Closed

Comments

@djgilcrease
Copy link
Contributor

.issue-59 {
    width:100%;
    width: -webkit-calc(100% + 30px);
    width: -moz-calc(100% + 30px);
    width: calc(100% + 30px);
}

turns into
.issue-59{width:100%;width:-webkit-calc(100%+30px);width:-moz-calc(100%+30px);width:calc(100%+30px)}

instead of

.issue-59{width:100%;width:-webkit-calc(100% + 30px);width:-moz-calc(100% + 30px);width:calc(100% + 30px)}

Notice the missing spaces

@ghost ghost assigned tml Mar 31, 2013
@tml
Copy link
Contributor

tml commented Mar 31, 2013

calc() is specifically called out as "at risk of being dropped during the CR period", but we should probably still address this one, as the blasted spec does - in fact - require at least one whitespace character around + and - operators.

@filipewl
Copy link

filipewl commented Apr 4, 2013

I'm having exactly the same problem. I'm using Jammit to compress the CSS for production and my calc() expressions are breaking because the compressor is removing, sometimes, spaces before and after operators and parenthesis.

Examples:
Original: calc(100% * 2 + 20px * (2 - 1))
Compressed: calc(100% * 2+20px *(2 - 1))

Does anybody know a workaround for this? I see no other option but to exclude this part of the CSS from Jammit's pipeline.

@alfredxing
Copy link

I'm having the same issue. Although calc is considered "experimental", it's a great tool to use (and it does work with major browsers).
It would be great to have this fixed; I can't seem to find a workaround.

@yetithefoot
Copy link

Same here! Vote for this!

@danielsamuels
Copy link

Me too.

@kmxz
Copy link

kmxz commented Aug 7, 2013

Same problem troubled me

@kris-o3
Copy link

kris-o3 commented Sep 3, 2013

background-position: calc(65% - (100px - 350px * 0.65)) 0;

gets compressed as:

background-position:calc(65% -(100px - 350px * .65)) 0;

i currently have to add a space after the - before the inner expression.
like so:

background-position:calc(65% - (100px - 350px * .65)) 0;

i have to do this every time i commit css-related changes.
it is making me very sad indeed.

@eaoliver
Copy link

Has there been any progress on this bug? It's maddening. Nested expressions are still being compressed, which breaks the calc function under Safari and Firefox. It works under Chrome.

Example: (source calcs had spaces been operations)

left: -moz-calc((100% - 106px)/2+64px);
left: -webkit-calc((100% - 106px)/2+64px);
left: calc((100% - 106px)/2+64px);

@kris-o3
Copy link

kris-o3 commented Sep 30, 2013

i attempted to locate which of the many regex's might need tweaking for this but was caught up in the muck and mire of a very long if( ) statement indeed... surely someone who worked on it or familiar with it can have a look?

@djgilcrease djgilcrease mentioned this issue Sep 30, 2013
@djgilcrease
Copy link
Contributor Author

We had fixed this in our local version, I just forgot to commit it back for upstream pull request #107

@kris-o3
Copy link

kris-o3 commented Sep 30, 2013

great! let us know when the merge has been approved / is complete?

@tml
Copy link
Contributor

tml commented Sep 30, 2013

The PR breaks the build, but it's a huge step forward. Thanks, @djgilcrease!

@djgilcrease
Copy link
Contributor Author

How does it break the build? I was able to run the ant build and all the tests that were passing before changes were still passing.

@tml
Copy link
Contributor

tml commented Sep 30, 2013

See the Travis status on #107

Or just check the build: https://travis-ci.org/yui/yuicompressor/builds/11968385

@kris-o3
Copy link

kris-o3 commented Sep 30, 2013

not familiar with 'checking the build' but i see that it "failed" ?
will it be tagged w/ a new version # when this fix is ready for prime-time?

@tml
Copy link
Contributor

tml commented Sep 30, 2013

This will likely be part of 2.4.9, unless there's a strong objection from the user community.

@eaoliver
Copy link

What's the ETA on 2.4.9?

@djgilcrease
Copy link
Contributor Author

Ok, will get the build passing again

@djgilcrease
Copy link
Contributor Author

Build is passing for pull request #107 again https://travis-ci.org/yui/yuicompressor/builds/11977764

@kris-o3
Copy link

kris-o3 commented Oct 21, 2013

fixed upon fixing issue #59?

#107

@jlong
Copy link

jlong commented Dec 2, 2013

Can we get this merged please? Looks like it's ready to go.

@djgilcrease
Copy link
Contributor Author

Just checking on the status of this since the build tests have been passing for 4 months now

@patrick91
Copy link

Any update on this?

@beaktor
Copy link

beaktor commented Feb 19, 2014

One nice option: use simple math and do a double negative. The bug doesn't seem to affect the - operator, just +.

Replace this:

width: calc(100% + 20px)

With this:

width: calc(100% - -20px);

@kris-o3
Copy link

kris-o3 commented Feb 19, 2014

interesting (?) workaround -- supported by all browsers?

@djgilcrease
Copy link
Contributor Author

it is, but it does not fix multiplication or division issues

@manishmp7
Copy link

facing same issue
I'm using "2.4.8" version.

Team, Please fix it or tell me how can i fix it without (- -) solution

@svaponi
Copy link

svaponi commented Sep 19, 2017

Compression examples:

calc(50% - 3px)      => calc(50% - 3px)   // VALID
calc(50% + 3px)      => calc(50%+3px)     // INVALID
calc(50% + +3px)     => calc(50%++3px)    // INVALID
calc((50%) + (3px))  => calc((50%)+(3px)) // INVALID
calc(50% + (+3px))   => calc(50%+(+3px))  // INVALID
calc(50% + (3px))    => calc(50%+(3px))   // INVALID
calc(50% - (-3px))   => calc(50% -(-3px)) // INVALID
calc(50% - -3px)     => calc(50% - -3px)  // VALID

@PeterLenahan
Copy link

Before compression spaces are there
.file-item {
width: calc(100vw - 40px);
height: calc(((100vw - 40px) * .73) + 40px);
}
After compression, the spaces are missing.

.file-item{width:calc(100vw - 40px);height:calc(((100vw - 40px) * .73)+40px)}

@sunnybear
Copy link

Any news on this? YUI Compressor breaks CSS calc for 5 years!

@himanshuwt
Copy link

@sunnybear agree with you. 5 years done. And, still I faced the issue "+" then again i replace it with calc(x - - y). :D

@sunnybear
Copy link

Does anybody have a list of issues with calc? We've faced with
100% + 6px -> 100%+px
100% - (10% * 6) -> 100% -(10% * 6)
It seems also
(100vw - 40px) * .73) + 40px -> (100vw - 40px) * .73)+ 40px

@MarjanAshofteh
Copy link

MarjanAshofteh commented Jun 4, 2018

@beaktor
using two - beside + works for me too.
thanks

PaulCapron added a commit to PaulCapron/pwa2uwp that referenced this issue Nov 14, 2018
See yui/yuicompressor#59

The spec mandates spaces around ‘+’ and ‘-’. Chrome is lax on that rule tho,
but Firefox (and possibly others) ain’t!
@ramarro123
Copy link

it's yui compressor still mantained?

siovene added a commit to astrobin/astrobin that referenced this issue Mar 6, 2019
@DrLightman
Copy link

Using YuiCompressor 2.4.8 and the bug is still on.

@frangarcia
Copy link

frangarcia commented Jun 4, 2020

This version, https://mvnrepository.com/artifact/com.yahoo.platform.yui/yuicompressor/2.4.9-BSI-2, seems to have fixed the problem. I followed the examples @svaponi added using this file

body{
	font-size: calc(50% - 3px);
	font-size: calc(50% + 3px);
	font-size: calc(50% + +3px);
	font-size: calc((50%) + (3px));
	font-size: calc(50% + (+3px));
	font-size: calc(50% + (3px));
	font-size: calc(50% - (-3px));
	font-size: calc(50% - -3px);
}

and when running this command:

java -jar yuicompressor-2.4.9-BSI-2.jar --line-break 0 -o process.css.min file.css

this output was generated:

body{font-size:calc(50% - 3px);font-size:calc(50% + 3px);font-size:calc(50% + +3px);font-size:calc((50%)+(3px));font-size:calc(50% + (+3px));font-size:calc(50% + (3px));font-size:calc(50% - (-3px));font-size:calc(50% - -3px)}

which looks correct.

It seems the repo in charge of this is this fork https://github.com/BSI-Business-Systems-Integration-AG/yuicompressor

@Aleuck
Copy link

Aleuck commented Aug 23, 2020

This is not correct, @frangarcia
calc((50%)+(3px))

siovene added a commit to astrobin/astrobin that referenced this issue Oct 2, 2020
berinhard added a commit to python/pythondotorg that referenced this issue Nov 17, 2020
The previous code lead to an invalid value for the left property:

`left: calc(-50vw+50%);`

This was being caused due to a bug in YUI Compressor. You can read
a detailed explanation about it in this issue:

yui/yuicompressor#59


This is fixed since version 2.4.9-BSI-2. But, until we don't update
prod's YUI Compressor, this PR work as a bugfix since it changes the
parameters order to one properly understood by the bugged version.
More aboute this in this issue comment:

yui/yuicompressor#59 (comment)
ewdurbin pushed a commit to python/pythondotorg that referenced this issue Nov 17, 2020
The previous code lead to an invalid value for the left property:

`left: calc(-50vw+50%);`

This was being caused due to a bug in YUI Compressor. You can read
a detailed explanation about it in this issue:

yui/yuicompressor#59


This is fixed since version 2.4.9-BSI-2. But, until we don't update
prod's YUI Compressor, this PR work as a bugfix since it changes the
parameters order to one properly understood by the bugged version.
More aboute this in this issue comment:

yui/yuicompressor#59 (comment)
mathjazz pushed a commit to mathjazz/pontoon that referenced this issue Feb 11, 2021
The + and - operators in CSS calc() must be surrounded by whitespace:
https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#notes

The yuglify CSS compressor we use removes them and breaks CSS.
I tried yuicompressor instead, which has the same bug:
yui/yuicompressor#59

Other CSS compressors I've checked look (even more) outdated.
I haven't tested any.

The only other instance of calc() in our code uses - instead of +,
which is fine.
mathjazz added a commit to mathjazz/pontoon that referenced this issue Feb 11, 2021
The + and - operators in CSS calc() must be surrounded by whitespace:
https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#notes

The yuglify CSS compressor we use removes them and breaks CSS.
I tried yuicompressor instead, which has the same bug:
yui/yuicompressor#59

Other CSS compressors I've checked look (even more) outdated.
I haven't tested any.

The only other instance of calc() in our code uses - instead of +,
which is fine.
mathjazz added a commit to mozilla/pontoon that referenced this issue Feb 12, 2021
Our default CSS compressor removes whitespace around + and - in calc(), which are significant:
https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#notes

None of the CSS compressors seems to be prone to this bug, here's another:
yui/yuicompressor#59

We shouldn't constrain our CSS by bugs in that pipeline.

Instead, let's use a no-op css compressor to cat the files together.
siovene added a commit to astrobin/astrobin that referenced this issue Feb 18, 2021
@R-W-C
Copy link

R-W-C commented Sep 28, 2022

September 2022 and still broken.
Version 2.4.8 has got several bugs. One of them is described here: https://stackoverflow.com/a/19339287/760777
Version 2.4.9 has never been released.

So back to version 2.4.7
There is the calc bug. Just use the double minus solution.

So

left: calc(100% + 14px);

becomes

left: calc(100 - -14px); /* + replaced with - - because of yuicompressor bug */

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