mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-20 09:09:35 +02:00
fix(html-view): a ~/ HTML link renders as a page too (#547/#604 integration)
#604 makes `~/` links clickable and passes them through unchanged, since only the server knows the session host's home. The html-view mint read `~/x.html` as workspace-relative and answered 404, so the preview fell back to the source view. It now expands `~/` against this host's home, as the attachment route does, and refuses it in a Docker case (that `~` is the container's) with the same message as the attachment and folder routes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1172ef56f8
commit
5e83cd3885
4 files changed
+38
-8
No files matched your search
@@ -66,6 +66,24 @@ describe('html-view routes', () => {
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
it('expands a ~/ path against this host home, as the attachment route does', async () => {
|
||||
// test/setup.ts points HOME at a temp dir, so this never touches the real home.
|
||||
// The terminal passes a `~/` link through unchanged; only the server knows the home.
|
||||
const site = join(homedir(), 'html-view-tilde', 'site');
|
||||
mkdirSync(site, { recursive: true });
|
||||
writeFileSync(join(site, 'page.html'), '<h1>home</h1>');
|
||||
try {
|
||||
const res = await open('~/html-view-tilde/site/page.html');
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(JSON.parse(res.body).data.url).toMatch(/^\/html-view\/[A-Za-z0-9_-]{16,}\/page\.html$/);
|
||||
// A Docker case's `~` is the container's home, never this host's.
|
||||
(harness.ctx.sessions.get(sid) as { docker?: unknown }).docker = { caseName: 'c' };
|
||||
expect((await open('~/html-view-tilde/site/page.html')).statusCode).toBe(400);
|
||||
} finally {
|
||||
rmSync(join(homedir(), 'html-view-tilde'), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('validates the body', async () => {
|
||||
const post = (payload: unknown) =>
|
||||
harness.app.inject({ method: 'POST', url: `/api/sessions/${sid}/html-view`, payload: payload as object });
|
||||
|
||||
Reference in new issue
Block a user