SHA256
Проверить вложения и блоки в каналах
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { buildAttachmentBlock, parseMessageAttachments } from '../js/services/attachment-format.js';
|
||||
|
||||
const root = '4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi';
|
||||
const source = (name) => ({ name, size: 1837243, pr: root, mm: 'video/mp4' });
|
||||
test('v2: UTF-8 имена без лишних %-кодов', () => {
|
||||
const marker = buildAttachmentBlock(source('Водопад.mp4'));
|
||||
assert.match(marker, /^<S:att;v=2;nm=Водопад.mp4;sz=1837243;/u);
|
||||
assert.equal(parseMessageAttachments(`${marker}\nцук`).attachments[0].name, 'Водопад.mp4');
|
||||
assert.equal(parseMessageAttachments(`${marker}\nцук`).text, 'цук');
|
||||
});
|
||||
test('v2: только служебные символы экранируются; круговой обмен', () => {
|
||||
for (const name of ['Лето;фильм=1%.mp4', 'Привет<мир>.mp4', '中文;عربي=тест%.mp4']) {
|
||||
const marker = buildAttachmentBlock(source(name));
|
||||
assert.equal(parseMessageAttachments(marker).attachments[0].name, name);
|
||||
assert.equal(marker.includes('nm='+encodeURIComponent(name)), false);
|
||||
assert.doesNotMatch(marker, /nm=[^;]*;фильм/u);
|
||||
}
|
||||
});
|
||||
test('v1: прежние URI-имена остаются читаемыми', () => {
|
||||
const name = 'Водопад.mp4';
|
||||
const marker = `<S:att;v=1;nm=${encodeURIComponent(name)};sz=10;pr=${root};mm=video/mp4>`;
|
||||
assert.equal(parseMessageAttachments(marker).attachments[0].name, name);
|
||||
});
|
||||
test('v2: дубликаты, неизвестные поля и плохие escape не интерпретируются как вложение', () => {
|
||||
for (const body of [
|
||||
`v=2;nm=a;sz=10;sz=500;pr=${root}`,
|
||||
`v=2;nm=foo;bad=value;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc%zz;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc%3;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc%0Aevil;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc;sz=-1;pr=${root}`,
|
||||
`v=2;nm=abc;sz=01;pr=${root}`,
|
||||
`v=2;nm=abc<b;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc=d;sz=10;pr=${root}`,
|
||||
`v=2;nm=abc;sz=10;pr=${root};ar=wrong-id`,
|
||||
]) {
|
||||
assert.equal(parseMessageAttachments(`<S:att;${body}>`).attachments.length, 0, body);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user