fix: preserve delivered page links when auto images fail
This commit is contained in:
@@ -198,6 +198,27 @@ test('sanitizePublicHtmlLinksInText keeps existing own public html links', () =>
|
||||
}
|
||||
});
|
||||
|
||||
test('sanitizePublicHtmlLinksInText finds pages in the workspace beside H5_USERS_ROOT', () => {
|
||||
const owner = `test-user-${Date.now()}-shared-workspace`;
|
||||
const runtimeRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'memind-shared-workspace-'));
|
||||
const previousUsersRoot = process.env.H5_USERS_ROOT;
|
||||
const htmlPath = path.join(runtimeRoot, 'MindSpace', owner, 'public', 'poem.html');
|
||||
process.env.H5_USERS_ROOT = path.join(runtimeRoot, 'users');
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(htmlPath), { recursive: true });
|
||||
fs.writeFileSync(htmlPath, '<!doctype html><title>Poem</title>');
|
||||
const text =
|
||||
`[诗词页面](https://m.tkmind.cn/MindSpace/${owner}/public/poem.html)`;
|
||||
const next = sanitizePublicHtmlLinksInText(text, { id: owner, username: 'john' });
|
||||
assert.match(next, new RegExp(`/MindSpace/${owner}/public/poem\\.html`));
|
||||
assert.doesNotMatch(next, /页面生成未完成/);
|
||||
} finally {
|
||||
if (previousUsersRoot == null) delete process.env.H5_USERS_ROOT;
|
||||
else process.env.H5_USERS_ROOT = previousUsersRoot;
|
||||
fs.rmSync(runtimeRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('sanitizePublicHtmlLinksInText canonicalizes wrong MindSpace public hosts', () => {
|
||||
const owner = `test-user-${Date.now()}-canonical-host`;
|
||||
const previousBase = process.env.H5_PUBLIC_BASE_URL;
|
||||
|
||||
Reference in New Issue
Block a user