From 6497ce8438bc21792cf616ca9f3ae9ec891ecede Mon Sep 17 00:00:00 2001 From: Afloat Date: Wed, 18 Nov 2026 18:26:02 +0800 Subject: [PATCH 1/2] fix(client): include stylesheets imported after CSS comments Signed-off-by: Afloat --- client/main/conversation/stylesheet-references.js | 9 ++++++++- client/tests/task-delivery-lifecycle.test.cjs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/client/main/conversation/stylesheet-references.js b/client/main/conversation/stylesheet-references.js index 09ed24f93..b619de616 100644 --- a/client/main/conversation/stylesheet-references.js +++ b/client/main/conversation/stylesheet-references.js @@ -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; } diff --git a/client/tests/task-delivery-lifecycle.test.cjs b/client/tests/task-delivery-lifecycle.test.cjs index dd07f1de6..f8c64624a 100644 --- a/client/tests/task-delivery-lifecycle.test.cjs +++ b/client/tests/task-delivery-lifecycle.test.cjs @@ -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,")} @import "theme.css"; .b{src:url(font.woff2);background:url('hero image.png')}`), ['data:image/svg+xml,', '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', ''); + 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'), []); +}); From 4ef8c8dde92c081a6a47540c0fc049e3e5f6fe01 Mon Sep 17 00:00:00 2001 From: Afloat Date: Wed, 18 Nov 2026 20:35:03 +0800 Subject: [PATCH 2/2] fix(client): preserve literal comment-like stylesheet URLs Limit comment skipping to the value after @import so unquoted url() paths retain their literal content during delivery discovery. Signed-off-by: Afloat --- .../conversation/stylesheet-references.js | 14 +++++----- client/tests/task-delivery-lifecycle.test.cjs | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/main/conversation/stylesheet-references.js b/client/main/conversation/stylesheet-references.js index b619de616..294daf679 100644 --- a/client/main/conversation/stylesheet-references.js +++ b/client/main/conversation/stylesheet-references.js @@ -16,14 +16,7 @@ function references(source) { } return ''; } - 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; - } - } + function whitespace() { while (/\s/.test(text[i] || '') && i < text.length) i++; } 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; } @@ -31,6 +24,11 @@ function references(source) { if (!token || /[\w$.-]/.test(text[i - 1] || '')) { i++; continue; } i += token[0].length; whitespace(); if (token[0][0] === '@') { + while (text.startsWith('/*', i)) { + const end = text.indexOf('*/', i + 2); + i = end < 0 ? text.length : end + 2; + whitespace(); + } if (text[i] === '"' || text[i] === "'") result.push(string()); continue; } diff --git a/client/tests/task-delivery-lifecycle.test.cjs b/client/tests/task-delivery-lifecycle.test.cjs index f8c64624a..a41db9206 100644 --- a/client/tests/task-delivery-lifecycle.test.cjs +++ b/client/tests/task-delivery-lifecycle.test.cjs @@ -192,3 +192,29 @@ test('website delivery follows quoted CSS imports separated by comments', async assert.deepEqual(refs('@import /* one */ /* two */ "a.css"; /* @import "fake.css"; */'), ['a.css']); assert.deepEqual(refs('@import /* unclosed'), []); }); + +test('stylesheet URL tokenization preserves literal comment-like paths', () => { + const refs = require('../main/conversation/stylesheet-references').references; + for (const [css, expected] of [ + ['url(/*comment*/image.png)', '/*comment*/image.png'], + ['url( \t/*comment*/image.png )', '/*comment*/image.png'], + ['url(/*one*//*two*/image.png)', '/*one*//*two*/image.png'], + ['url(/*unfinished-image.png)', '/*unfinished-image.png'], + ['url(images/*comment*/image.png)', 'images/*comment*/image.png'], + ['url("/*comment*/image.png")', '/*comment*/image.png'], + ['@import/* import comment */url(/*literal*/theme.css)', '/*literal*/theme.css'], + ]) assert.deepEqual(refs(css), [expected], css); + assert.deepEqual(refs('@import/* comment */url( theme.css );'), ['theme.css']); +}); + +for (const [label, css, dependency] of [ + ['image', 'body{background-image:url(/*comment*/image.png)}', 'image.png'], + ['import', '@import/* import comment */url(/*literal*/theme.css);', 'theme.css'], +]) test('website delivery rejects a literal comment-like ' + label + ' URL instead of stripping it', async t => { + const f = workspace(t); + f.write('site/index.html', ''); + f.write('site/main.css', css); + f.write('site/' + dependency, dependency.endsWith('.css') ? 'body{color:purple}' : Buffer.from([137,80,78,71])); + await assert.rejects(delivery.capture(f.handle, 'completed'), /不适合交付的路径/); + assert.equal(fs.readFileSync(path.join(f.cwd, 'site/main.css'), 'utf8'), css); +});