chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
articleImageSource,
|
||||
ARTICLE_IMAGE_LIMIT,
|
||||
} from '../../src/components/common/ui/richTextImages.js';
|
||||
import {
|
||||
articleErrors,
|
||||
emptyInsights,
|
||||
newArticle,
|
||||
} from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
import {
|
||||
emptySettings,
|
||||
serializeSettings,
|
||||
} from '../../src/pages/WebsiteSettings/model.js';
|
||||
|
||||
const png =
|
||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=';
|
||||
|
||||
test('pasted images survive article validation and final JSON serialization without a cover field', () => {
|
||||
const article = {
|
||||
...newArticle('company'),
|
||||
id: 'pasted',
|
||||
title: '图文粘贴',
|
||||
summary: '摘要',
|
||||
body: `<h2>图文标题</h2><p>正文<img src="${png}"></p>`,
|
||||
};
|
||||
const insights = { ...emptyInsights(), articles: [article] };
|
||||
assert.deepEqual(articleErrors(article, insights), {});
|
||||
const restored = JSON.parse(
|
||||
serializeSettings({ ...emptySettings(), insights }),
|
||||
);
|
||||
assert.equal(restored.insights.articles[0].body, article.body);
|
||||
assert.equal('cover' in restored.insights.articles[0], false);
|
||||
});
|
||||
|
||||
test('image sources accept public URLs and bounded raster data, rejecting unsafe or temporary sources', () => {
|
||||
assert.equal(articleImageSource(png), png);
|
||||
assert.equal(
|
||||
articleImageSource('https://cdn.example.com/a.png'),
|
||||
'https://cdn.example.com/a.png',
|
||||
);
|
||||
for (const source of [
|
||||
'javascript:alert(1)',
|
||||
'blob:https://example.com/id',
|
||||
'/private/a.png',
|
||||
'file:///tmp/a.png',
|
||||
'https://user:pass@example.com/a.png',
|
||||
'data:image/svg+xml;base64,PHN2Zz4=',
|
||||
'data:text/html;base64,AAAA',
|
||||
'data:image/png;base64,notbase64!',
|
||||
])
|
||||
assert.equal(articleImageSource(source), '', source);
|
||||
const maximum = 'A'.repeat(Math.ceil(ARTICLE_IMAGE_LIMIT / 3) * 4 - 1) + '=';
|
||||
assert.ok(articleImageSource(`data:image/png;base64,${maximum}`));
|
||||
assert.equal(
|
||||
articleImageSource(
|
||||
`data:image/png;base64,${'A'.repeat(maximum.length + 4)}`,
|
||||
),
|
||||
'',
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user