Skip to content

Commit f9bfeca

Browse files
fix(builder): css hash incorrectly transforming data urls (#2921)
Fixes #2599
1 parent 2b0f76b commit f9bfeca

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/dev/builder_test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,35 @@ Deno.test({
9898
sanitizeResources: false,
9999
});
100100

101+
// Issue https://github.com/denoland/fresh/issues/2599
102+
Deno.test({
103+
name: "Builder - hashes CSS urls by default",
104+
fn: async () => {
105+
const builder = new Builder();
106+
const tmp = await Deno.makeTempDir();
107+
await Deno.writeTextFile(
108+
path.join(tmp, "foo.css"),
109+
`:root { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(76, 154.5, 137.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E"); }`,
110+
);
111+
const app = new App({
112+
staticDir: tmp,
113+
build: {
114+
outDir: path.join(tmp, "dist"),
115+
},
116+
});
117+
await builder.build(app);
118+
119+
const css = await Deno.readTextFile(
120+
path.join(tmp, "dist", "static", "foo.css"),
121+
);
122+
expect(css).toEqual(
123+
`:root { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(76, 154.5, 137.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E"); }`,
124+
);
125+
},
126+
sanitizeOps: false,
127+
sanitizeResources: false,
128+
});
129+
101130
Deno.test({
102131
name: "Builder - can bundle islands from JSR",
103132
fn: async () => {

src/dev/file_transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class FreshFileTransformer {
220220
}
221221
}
222222

223-
const CSS_URL_REGEX = /url\((["'][^'"]+["']|[^)]+)\)/g;
223+
const CSS_URL_REGEX = /url\(("[^"]+"|'[^']+'|[^)]+)\)/g;
224224

225225
export function cssAssetHash(transformer: FreshFileTransformer) {
226226
transformer.onTransform({

0 commit comments

Comments
 (0)