calc whitespace not always preserved #22

Closed
futtta opened this Issue Feb 24, 2015 · 11 comments

Comments

Projects
None yet
4 participants

futtta commented Feb 24, 2015

An Autoptimize-user has CSS with a calc in it which gets broken. Whereas YUI-CSS-compressor-PHP-port normally preserves spaces, it does not in this case (confirmed using GUI)

Test input;
input { width: calc(100% - (1em*1.5)); }

Expected output:
input{width:calc(100% - (1em*1.5))}

Actual Output:
input{width:calc(100% -(1em*1.5))}

Frank

futtta added a commit to futtta/YUI-CSS-compressor-PHP-port that referenced this issue Nov 28, 2015

@futtta futtta referenced this issue in mrclay/minify Feb 1, 2016

Closed

Incorrect minification in CSS calc() #503

rostik commented Oct 4, 2016

seems like it fixes "- (" but not ") -"

futtta added a commit to futtta/YUI-CSS-compressor-PHP-port that referenced this issue Oct 4, 2016

futtta commented Oct 4, 2016

can you try with this commit @rostik ?

rostik commented Oct 4, 2016

@futtta that didnt work, but i did this, not sure if its correct, but it worked

$this->preserved_tokens[] = preg_replace('/([+-]{1})(/','/$1 (/',trim(preg_replace('/\s_([_/(),])/', '$1', $matches[2])));

futtta commented Oct 4, 2016

yeah, had a stupid mistake in my code (forgot re-replacing $calc by $matches[2]) cfr. this commit.

can you try again?

rostik commented Oct 4, 2016

this works. thanks! @futtta

futtta commented Oct 4, 2016

great, thanks for testing & confirming! :-)

futtta added a commit to futtta/autoptimize that referenced this issue Oct 4, 2016

Can this fix be implemented into the mainline please?

Owner

tubalmartin commented Mar 26, 2017

Thank you for the fix. I'll release it this week ;)

futtta commented Mar 26, 2017

great to see you're back @tubalmartin :-)

Owner

tubalmartin commented Mar 26, 2017

Fixed in v2.4.8-p7 release. Thank you guys!

Furniel added a commit to Furniel/W3-Total-Cache that referenced this issue May 4, 2017

Merge branch 'YUI-CSS-compressor-PHP-3x' into Minify_2.3.1
YUI-CSS-compressor-PHP-3x official changelog:

### v3.1.2 17 Apr 2017

* Improved compression of long named colors: now all long named colors get compressed to their shorter HEX counterpart.
* Fixes cases such as [#39](tubalmartin/YUI-CSS-compressor-PHP-port#39)
* Huge performance improvement after code profiling. See table below for results when running the whole test suite:

PHP version used: 5.3.29

| chunkLength | v3.1.1 | v3.1.2 |
| --- | --- | --- |
| 100 | 6.8s | 2.6s |
| 1000 | 5.3s | 2s |
| 2000 | 5.2s | 1.95s |
| 5000 | 5.1s | 1.9s |

PHP version used: 7.0.8

| chunkLength | v3.1.1 | v3.1.2 |
| --- | --- | --- |
| 100 | 2s | 0.72s |
| 1000 | 1s | 0.37s |
| 2000 | 0.8s | 0.33s |
| 5000 | 0.7s | 0.3s |

### v3.1.1 11 Apr 2017

* Regexes improved.
* Small performance improvements.
* Blocks such as `@media` blocks with empty rules are removed too.
* Quoted unquotable attribute selectors get unquoted now i.e. from `col[class*="col-"]` to `col[class*=col-]`. Covers most common cases. Safe approach.

### v3.1.0 9 Apr 2017

* Code deeply analyzed. Some areas rewritten from the ground up with maximum performance in mind. No change in compressor behavior.
* Fixed some hidden bugs discovered along the way that affected performance negatively.
* IE5/Mac comment hack removed from minifier logic. Those comments will no longer be preserved.
* The table below displays the performance optimization done in this version in comparison with the previous one running the whole test suite:

PHP version used: 5.3.29

| chunkLength | v3.0.0 | v3.1.0 |
| --- | --- | --- |
| 100 | 38s | 6.9s |
| 1000 | 8.5s | 5.4s |
| 2000 | 7.3s | 5.3s |
| 5000 | 5.8s | 5.2s |

PHP version used: 7.0.8

| chunkLength | v3.0.0 | v3.1.0 |
| --- | --- | --- |
| 100 | 22.8s | 2.1s |
| 1000 | 2.9s | 1.1s |
| 2000 | 2s | 0.9s |
| 5000 | 1.3s | 0.8s |

### v3.0.0 4 Apr 2017

* New API compliant with PSR-1, PSR-2 & PSR-4. PHP 5.3.2+ required. I think it was time!
* Many tests added, strengthened and fixed. Big, real life, stylesheets included such as Bootstrap or Foundation.
* Fixed some critical and minor issues, such as:
   * Chunking system breaking some stylesheets (broken at rules block) or leaving some bits off.
   * Backreferences in replacement strings breaking stylesheets.
   * [#23](tubalmartin/YUI-CSS-compressor-PHP-port#23)
   * Others...
* Color compression improved. Now all named colors are supported i.e. from `white` to `#fff`.
* Shortening zero values is back but in a safe manner, shortening values assigned to "safe" properties only i.e. from `margin: 1px 0.0em 0rem 0%` to `margin:1px 0 0`. Check the code to see the list of "safe" properties.
* `padding` and `margin` properties are shortened to the bare minimum i.e. from `margin: 3px 2.1em 3px 2.1em` => `margin:3px 2.1em`
* Upgrading to v3 is strongly recommended for users enjoying PHP 5.3.2+.

### v2.4.8-p10 4 Apr 2017

* This is the last v2 release. v3 onwards will only support PHP 5.3.2+.
* This patch has all improvements and fixes v3.0.0 has. See v3.0.0 notes for further info (no API change in this version of course).
* Updating to this patch is strongly recommended for users stuck with PHP versions lower than PHP 5.3.

### v2.4.8-p9 28 Mar 2017

* Rolling back property declaration with scalar expressions (>= PHP 5.6) introduced in v2.4.8-p8 to support PHP 5.0. No change in compressor behavior.

### v2.4.8-p8 27 Mar 2017

* Fixed issue [#18](tubalmartin/YUI-CSS-compressor-PHP-port#18)
* Added `set_chunk_length` method.
* `bold` & `normal` values get compressed to `700` & `400` respectively for `font-weight` property.
* GUI updated.
* FineDiff library loaded through Composer.
* README updated.

### v2.4.8-p7 26 Mar 2017

* Fixed many issues [#20](tubalmartin/YUI-CSS-compressor-PHP-port#20), [#22](tubalmartin/YUI-CSS-compressor-PHP-port#22), [#24](tubalmartin/YUI-CSS-compressor-PHP-port#24), [#25](tubalmartin/YUI-CSS-compressor-PHP-port#25), [#26](tubalmartin/YUI-CSS-compressor-PHP-port#26) reported by contributors and others that I'm sure haven't been reported, at least yet. Sorry for the long delay guys.
* This release is all about stability and reliability and as such I've had to take some controversial decisions such as:
   * Not minifying `none` property value to `0` because in some subtle scenarios the resulting output may render some styles differently.
   * Not removing units from zero length values because in many cases the output will break the intended behavior. Patching every single case after someone finds a new breaking case is not good IMHO taking into account CSS is a live spec and browsers differ in some cases.
* Hope you agree with me removing those conflicting parts. Enjoy this release :)

### v2.4.8-p6 21 Mar 2017

* Fixed PHP CLI issues. See [#36](tubalmartin/YUI-CSS-compressor-PHP-port#36)

### v2.4.8-p5 27 Feb 2017

* Fixed PHP 7 issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment