mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
@@ -76,3 +76,55 @@ Generated by [AVA](https://avajs.dev).
|
||||
url: 'http://example.com/page',
|
||||
videos: [],
|
||||
}
|
||||
|
||||
> Snapshot 5
|
||||
|
||||
{
|
||||
charset: 'gbk',
|
||||
favicons: [
|
||||
'http://localhost:3010/api/worker/image-proxy?url=https%3A%2F%2Fexample.com%2Ffavicon.ico',
|
||||
],
|
||||
images: [],
|
||||
title: '你好,世界。',
|
||||
url: 'http://example.com/gb2312',
|
||||
videos: [],
|
||||
}
|
||||
|
||||
> Snapshot 6
|
||||
|
||||
{
|
||||
charset: 'shift_jis',
|
||||
favicons: [
|
||||
'http://localhost:3010/api/worker/image-proxy?url=https%3A%2F%2Fexample.com%2Ffavicon.ico',
|
||||
],
|
||||
images: [],
|
||||
title: 'こんにちは、世界。',
|
||||
url: 'http://example.com/shift-jis',
|
||||
videos: [],
|
||||
}
|
||||
|
||||
> Snapshot 7
|
||||
|
||||
{
|
||||
charset: 'big5',
|
||||
favicons: [
|
||||
'http://localhost:3010/api/worker/image-proxy?url=https%3A%2F%2Fexample.com%2Ffavicon.ico',
|
||||
],
|
||||
images: [],
|
||||
title: '你好,世界。',
|
||||
url: 'http://example.com/big5',
|
||||
videos: [],
|
||||
}
|
||||
|
||||
> Snapshot 8
|
||||
|
||||
{
|
||||
charset: 'euc-kr',
|
||||
favicons: [
|
||||
'http://localhost:3010/api/worker/image-proxy?url=https%3A%2F%2Fexample.com%2Ffavicon.ico',
|
||||
],
|
||||
images: [],
|
||||
title: '안녕하세요, 세계.',
|
||||
url: 'http://example.com/euc-kr',
|
||||
videos: [],
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -171,4 +171,56 @@ test('should preview link', async t => {
|
||||
|
||||
fetchSpy.restore();
|
||||
}
|
||||
|
||||
{
|
||||
const encoded = [
|
||||
{
|
||||
content: 'xOO6w6OsysC956Gj',
|
||||
charset: 'gb2312',
|
||||
},
|
||||
{
|
||||
content: 'grGC8YLJgr+CzYFBkKKKRYFC',
|
||||
charset: 'shift-jis',
|
||||
},
|
||||
{
|
||||
content: 'p0GmbqFBpUCsyaFD',
|
||||
charset: 'big5',
|
||||
},
|
||||
{
|
||||
content: 'vsiz58fPvLy/5CwgvLyw6C4=',
|
||||
charset: 'euc-kr',
|
||||
},
|
||||
];
|
||||
|
||||
for (const { content, charset } of encoded) {
|
||||
const before = Buffer.from(`<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=${charset}" />
|
||||
<meta property="og:title" content="`);
|
||||
const encoded = Buffer.from(content, 'base64');
|
||||
const after = Buffer.from(`" />
|
||||
</head>
|
||||
</html>
|
||||
`);
|
||||
const fakeHTML = new Response(Buffer.concat([before, encoded, after]));
|
||||
|
||||
Object.defineProperty(fakeHTML, 'url', {
|
||||
value: `http://example.com/${charset}`,
|
||||
});
|
||||
|
||||
const fetchSpy = Sinon.stub(global, 'fetch').resolves(fakeHTML);
|
||||
|
||||
await assertAndSnapshot(
|
||||
'/api/worker/link-preview',
|
||||
'should decode HTML content with charset',
|
||||
{
|
||||
status: 200,
|
||||
method: 'POST',
|
||||
body: { url: `http://example.com/${charset}` },
|
||||
}
|
||||
);
|
||||
|
||||
fetchSpy.restore();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user