lightningcss icon indicating copy to clipboard operation
lightningcss copied to clipboard

Unable to parse specific css urls

Open ezzak opened this issue 9 months ago • 0 comments

Minimal repro:

const {transform} = require('lightningcss');
const {Buffer} = require('node:buffer');

transform({
    code: Buffer.from(`.foo {
      background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>");
      backgroundColor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"></svg>');
    }`),
    minify: true,
  });

This produces an error when parsing the second url, (double quotes inside single quotes). Escaping does not seem to help either.

WASM / playground version does not seem to have the same issue as it is re-applying the quotes (flipping single and double)

https://lightningcss.dev/playground/#%7B%22minify%22%3Atrue%2C%22customMedia%22%3Afalse%2C%22cssModules%22%3Afalse%2C%22analyzeDependencies%22%3Afalse%2C%22targets%22%3A%7B%22chrome%22%3A6225920%7D%2C%22include%22%3A0%2C%22exclude%22%3A0%2C%22source%22%3A%22.foo%20%7B%5Cn%20%20background%3A%20url(%5C%22data%3Aimage%2Fsvg%2Bxml%2C%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%3E%3C%2Fsvg%3E%5C%22)%3B%5Cn%20%20backgroundColor%3A%20url('data%3Aimage%2Fsvg%2Bxml%2C%3Csvg%20xmlns%3D%5C%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%5C%22%3E%3C%2Fsvg%3E')%3B%5Cn%7D%22%2C%22visitorEnabled%22%3Afalse%2C%22visitor%22%3A%22%7B%5Cn%20%20Color(color)%20%7B%5Cn%20%20%20%20if%20(color.type%20%3D%3D%3D%20'rgb')%20%7B%5Cn%20%20%20%20%20%20color.g%20%3D%200%3B%5Cn%20%20%20%20%20%20return%20color%3B%5Cn%20%20%20%20%7D%5Cn%20%20%7D%5Cn%7D%22%2C%22unusedSymbols%22%3A%5B%5D%2C%22version%22%3A%22local%22%7D

ezzak avatar Mar 24 '25 18:03 ezzak