Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion client/main/conversation/stylesheet-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ function references(source) {
}
return '';
}
function whitespace() { while (/\s/.test(text[i] || '') && i < text.length) i++; }
function whitespace() {
while (i < text.length) {
if (/\s/.test(text[i])) { i++; continue; }
if (!text.startsWith('/*', i)) break;
const end = text.indexOf('*/', i + 2);
i = end < 0 ? text.length : end + 2;
}
}
while (i < text.length) {
if (text.startsWith('/*', i)) { const end = text.indexOf('*/', i + 2); i = end < 0 ? text.length : end + 2; continue; }
if (text[i] === '"' || text[i] === "'") { string(); continue; }
Expand Down
14 changes: 14 additions & 0 deletions client/tests/task-delivery-lifecycle.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ test('stylesheet URL tokenization ignores nested data content, comments and stri
assert.deepEqual(refs(`/* url(fake.png) */ .a{content:"url(fake2.png)";background:url("data:image/svg+xml,<svg filter='url(%23n)'/>")} @import "theme.css"; .b{src:url(font.woff2);background:url('hero image.png')}`),
['data:image/svg+xml,<svg filter=\'url(%23n)\'/>', 'theme.css', 'font.woff2', 'hero image.png']);
});

test('website delivery follows quoted CSS imports separated by comments', async t => {
const f = workspace(t);
f.write('site/index.html', '<link rel="stylesheet" href="main.css">');
f.write('site/main.css', '@import/* generated theme */ "theme.css";');
f.write('site/theme.css', 'body{background:url(bg.png)}');
f.write('site/bg.png', Buffer.from([137,80,78,71]));
const payload = await delivery.capture(f.handle, 'completed');
assert.deepEqual(payload.files.map(row => row.name).sort(),
['site/bg.png', 'site/index.html', 'site/main.css', 'site/theme.css']);
const refs = require('../main/conversation/stylesheet-references').references;
assert.deepEqual(refs('@import /* one */ /* two */ "a.css"; /* @import "fake.css"; */'), ['a.css']);
assert.deepEqual(refs('@import /* unclosed'), []);
});
Loading