From 957bf0f6c1d5e2bc6ff34fdf901400292133a723 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:05:36 +0100 Subject: [PATCH] fix: keep the 404 parent link on this site An address with an empty segment (//other.example/x) made the 404 page fetch and link a page of another site. Empty and dot segments are dropped, and a parent is fetched only on this site, under its base. --- website/src/scripts/site.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/website/src/scripts/site.ts b/website/src/scripts/site.ts index ae5da4d19..d83ac74c1 100644 --- a/website/src/scripts/site.ts +++ b/website/src/scripts/site.ts @@ -1397,11 +1397,14 @@ const notFound = () => { } if (lines.length) show(...lines); // A section below a page: the nearest page above it that exists. - const parts = rest.replace(/\/$/, '').split('/'); + // Empty segments dropped: "//host/x" would read as another site's address. + const parts = rest.split('/').filter((part) => part && part !== '.' && part !== '..'); const parents = parts.slice(0, -1).map((_, index) => parts.slice(0, parts.length - 1 - index).join('/')); (async () => { for (const parent of parents) { const url = new URL(`${parent}/`, siteRoot()); + // Only a page of this site, under its base, is fetched or linked. + if (url.origin !== siteRoot().origin || !url.pathname.startsWith(siteRoot().pathname)) return; try { if ((await fetch(url, { method: 'HEAD' })).ok) { const link = document.createElement('a');