fix(mindspace): canonicalize public page links without MindSpace segment
This commit is contained in:
@@ -216,6 +216,37 @@ test('sanitizePublicHtmlLinksInText canonicalizes wrong MindSpace public hosts',
|
||||
}
|
||||
});
|
||||
|
||||
test('sanitizePublicHtmlLinksInText canonicalizes public html links missing MindSpace segment', () => {
|
||||
const owner = `test-user-${Date.now()}-missing-mindspace`;
|
||||
const previousBase = process.env.H5_PUBLIC_BASE_URL;
|
||||
process.env.H5_PUBLIC_BASE_URL = 'https://m.tkmind.cn';
|
||||
const htmlPath = path.join(process.cwd(), 'MindSpace', owner, 'public', 'kuanting-plan.html');
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(htmlPath), { recursive: true });
|
||||
fs.writeFileSync(htmlPath, '<!doctype html><title>宽庭</title>');
|
||||
const text =
|
||||
`[宽庭方案](https://mindspace.tkmind.com/${owner}/public/kuanting-plan.html)`;
|
||||
const next = sanitizePublicHtmlLinksInText(text, { id: owner, username: 'john' });
|
||||
assert.doesNotMatch(next, /mindspace\.tkmind\.com/);
|
||||
assert.match(
|
||||
next,
|
||||
new RegExp(`https://m\\.tkmind\\.cn/MindSpace/${owner}/public/kuanting-plan\\.html`),
|
||||
);
|
||||
assert.doesNotMatch(next, /页面生成未完成/);
|
||||
} finally {
|
||||
if (previousBase == null) delete process.env.H5_PUBLIC_BASE_URL;
|
||||
else process.env.H5_PUBLIC_BASE_URL = previousBase;
|
||||
fs.rmSync(path.join(process.cwd(), 'MindSpace', owner), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('sanitizePublicHtmlLinksInText leaves other users missing-MindSpace links unchanged', () => {
|
||||
const owner = `test-user-${Date.now()}-other-missing-mindspace`;
|
||||
const text = `[外部页面](https://mindspace.tkmind.com/${owner}/public/kuanting-plan.html)`;
|
||||
const next = sanitizePublicHtmlLinksInText(text, { id: `current-${owner}`, username: 'john' });
|
||||
assert.equal(next, text);
|
||||
});
|
||||
|
||||
test('sanitizeSessionConversationPublicHtmlLinks updates text items inside conversation messages', () => {
|
||||
const owner = `test-user-${Date.now()}-conversation`;
|
||||
const publicRoot = path.join(process.cwd(), 'MindSpace', owner, 'public');
|
||||
|
||||
Reference in New Issue
Block a user