matype / stylefmt

stylefmt is a tool that automatically formats stylesheets.
Other
2.1k stars 89 forks source link

Added support for Regex to determinate a data url #344

Open sveneberth opened 4 years ago

sveneberth commented 4 years ago

There is currently a problem with SVGs in data-urls.

background-image: url('data:image/svg+xml;utf8,<svg ...> ... </svg>');

After formatting stylefmt return this:

background-image: url('data:image/svg+xml;utf8, <svg ...> ... </svg>');

A space is added after the comma, but this is an incorrect syntax (see RFC2397).

The reason for this incorrect syntax is that stylefmt expects data-urls encoded as base64, but this is still not required by the rfc.

Therefore I removed the base64 part in the regex to allow data ASCII data as well. The data: must be enough as indicator.

Of course we can match the base64 in the regex but this only a test and therefor I reduced it as far as possible. Alternative would be:

/data:.+\/(.+)(;base64)?,(.*)/