fix(css): stringify unquoted data urls (#3877)

master
Evilebot Tnawi 2018-02-02 20:39:53 +03:00 committed by GitHub
parent f5e74cd70a
commit ed2a9be58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 1 deletions

View File

@ -39,6 +39,25 @@ function parseValueNodes(nodes) {
for (let i = 0; i < nodes.length; ++i) {
const node = nodes[i];
const isUnquotedDataURLCall =
node.type === "func" &&
node.value === "url" &&
node.group &&
node.group.groups &&
node.group.groups[0] &&
node.group.groups[0].groups &&
node.group.groups[0].groups.length > 2 &&
node.group.groups[0].groups[0].type === "word" &&
node.group.groups[0].groups[0].value === "data" &&
node.group.groups[0].groups[1].type === "colon" &&
node.group.groups[0].groups[1].value === ":";
if (isUnquotedDataURLCall) {
node.group.groups = [stringifyGroup(node)];
return node;
}
if (node.type === "paren" && node.value === "(") {
parenGroup = {
open: node,
@ -86,6 +105,31 @@ function parseValueNodes(nodes) {
return rootParenGroup;
}
function stringifyGroup(node) {
if (node.group) {
return stringifyGroup(node.group);
}
if (node.groups) {
return node.groups.reduce((previousValue, currentValue, index) => {
return (
previousValue +
stringifyGroup(currentValue) +
(currentValue.type === "comma_group" && index !== node.groups.length - 1
? ","
: "")
);
}, "");
}
const before = node.raws && node.raws.before ? node.raws.before : "";
const value = node.value ? node.value : "";
const unit = node.unit ? node.unit : "";
const after = node.raws && node.raws.after ? node.raws.after : "";
return before + value + unit + after;
}
function flattenGroups(node) {
if (
node.type === "paren_group" &&

View File

@ -466,7 +466,7 @@ function genericPrint(path, options, print) {
n.groups[0].type === "value-comma_group" &&
n.groups[0].groups.length > 0 &&
n.groups[0].groups[0].type === "value-word" &&
n.groups[0].groups[0].value === "data"))
n.groups[0].groups[0].value.startsWith("data:")))
) {
return concat([
n.open ? path.call(print, "open") : "",

View File

@ -18,6 +18,7 @@ exports[`inline_url.css 1`] = `
-fb-sprite: url(fbglyph:cross-outline, fig-white);
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=);
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=");
background-image: url(data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.breadItem {
@ -26,6 +27,7 @@ exports[`inline_url.css 1`] = `
-fb-sprite: url(fbglyph:cross-outline, fig-white);
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=);
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=");
background-image: url(data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased);
}
`;

View File

@ -4,4 +4,5 @@
-fb-sprite: url(fbglyph:cross-outline, fig-white);
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=);
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO4/B8AAqgB0yr7dJgAAAAASUVORK5CYII=");
background-image: url(data:application/font-woff;charset=utf-8;base64,ThisIsNormalBut/+0ThisIsLowerCased);
}