mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-13 13:33:52 -06:00
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.
This commit is contained in:
1 parent
29aeccba3c
commit
957bf0f6c1
1 file changed
+4
-1
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user