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

Numbers with decimals break processing of rgb() function in legacy format #435

Open
EreMaijala opened this issue Nov 28, 2024 · 1 comment

Comments

@EreMaijala
Copy link

EreMaijala commented Nov 28, 2024

Version tested: 1.3.73

Looks like decimals cause something to go wrong when processing an rgb() function with decimal numbers in legacy format.

Almost self-sufficient example:

<?php

include __DIR__ . '/vendor/autoload.php';

use MatthiasMullie\Minify\CSS;

$src = '.btn-link{color:rgb(40,86,136);background-color:rgba(0,0,0,0)}';
$minifier = new CSS($src);
echo "SRC: $src" . PHP_EOL;
echo 'OK:  ' . $minifier->execute() . PHP_EOL;
echo PHP_EOL;

$src = '.btn-link{color:rgb(40.75,86.75,136.5);background-color:rgba(0,0,0,0)}';
$minifier = new CSS($src);
echo "SRC: $src" . PHP_EOL;
echo 'BAD: ' . $minifier->execute() . PHP_EOL;


This outputs:

SRC: .btn-link{color:rgb(40,86,136);background-color:rgba(0,0,0,0)}
OK:  .btn-link{color:#285688;background-color:#fff0}

SRC: .btn-link{color:rgb(40.75,86.75,136.5);background-color:rgba(0,0,0,0)}
BAD: .btn-link{color:#fff0}

The second output (BAD) is obviously not correct.

As far as I can see the decimals are valid in CSS, also in the legacy rgb syntax.

@EreMaijala
Copy link
Author

Looks like the regex's in cleanupModernColors are a bit too eager and run past the closing parenthesis. Perhaps it would be enough to replace [^\s] with [^\s)], though I'm not quite sure about that.

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

1 participant