ben-eb / perfectionist

Beautify CSS files.
MIT License
228 stars 14 forks source link

Base 64 encoded images #43

Closed Mottie closed 8 years ago

Mottie commented 8 years ago

When a css definition includes a hex color and a base 64 encoded image, the image is converted to all lower case. For example, given this css:

.arrows {
  background: #181818 url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAUCAQAAAAua3X8AAAARklEQVR4AWNABWcazjQg8zGl/wNhA15piBL80gglmNKYSjClMZUgpDGVwKXxKBl4QNiRBLxJIKAIBzXhyCIc3YQTDMEkBwBplPJRxEMa4wAAAABJRU5ErkJggg==");
}

the applyTransformFeatures function will determine that the following rule.value is a hex color:

#181818 url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAUCAQAAAAua3X8AAAARklEQVR4AWNABWcazjQg8zGl/wNhA15piBL80gglmNKYSjClMZUgpDGVwKXxKBl4QNiRBLxJIKAIBzXhyCIc3YQTDMEkBwBplPJRxEMa4wAAAABJRU5ErkJggg==")

From looking at the code, no matter the setting of the colorCase option, this image URI will be destroyed by applying a .toLowerCase() function at line 303 or .toUpperCase() function at line 305 of the index.js file.

Restoring the start and end anchors of the isHexColor.js match regex (removed in pr #36), would fix this issue, but I didn't test if anything else would break.

exports.default = function (color) {
  return color.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/) !== null;
};
ben-eb commented 8 years ago

Perhaps it might be better to switch to https://github.com/TrySound/postcss-value-parser instead of using regular expressions here.

ben-eb commented 8 years ago

I've begun a transition.

https://github.com/ben-eb/perfectionist/pull/44

Mottie commented 8 years ago

Edit: oops, I added a comment in the wrong place!

Mottie commented 8 years ago

Thanks for all the hard work!

ben-eb commented 8 years ago

Pleasure! 😄