Skip to content

Fraction optimizer (level 1) breaks image-set URLs containing zeros and dots #1183

Description

@squiddy

@tomyo and I noticed an issue where running clean-css over our CSS would sometimes mangle image URLs that contain zeros and dots, e.g. assets containing a hash generated by webpack.

For example category_book_medicine@2x.90ab2594.png would get changed to category_book_medicine@2x.9ab2594.png (zero removed).

Environment

  • clean-css version - master / 5.1.5:
  • node.js version - 12.21.0:
  • operating system: Pop!_OS 21.04

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS({
  level: 1
})

Input CSS

div { 
  background: image-set(url('foo.10.png') 1x); 
}

Actual output CSS

div{background:image-set(url('foo.1.png') 1x)}

Note how 10 was changed to 1. This can also observed with URLs such as 10.10.png, which get's changed to 10.1.png.

Expected output CSS

div{background:image-set(url('foo.10.png') 1x)}

Culprit

We could trace this issue back to the optimizations happening in fraction.js. Disabling just this one optimization returns the expected result. There are a couple other optimizations that return early when their input is considered an URL (startsAsUrl), however in the case of image-set that function returns false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions