leave a page to the client when a path component is too long for a file name
Signed-off-by: dawn <90008@klbr.net>
159 unmodified linesExpand all160161162163164165166167168169170171172173169174175176177178392 unmodified linesExpand all159 unmodified linesExpand all
// lists whose later pages get pages of their ownconst PAGED = new Set(["commits", "branches", "tags"]);
// a path component a file system takes, with room for "~page-N.html.gz" (most cap a name at// 255 bytes, git doesn't): a page whose name won't fit is left to the clientconst NAME_BYTES = 230;const fitsFile = (rest) => rest.split("/").every((name) => Buffer.byteLength(name) <= NAME_BYTES);
const routeOf = (prefix, route, repo) => { const paged = PAGE_QUERY.exec(route); const pathname = paged ? route.slice(0, paged.index) : route; if (pathname !== prefix && !pathname.startsWith(prefix + "/")) return null; const rest = pathname.slice(prefix.length); if (NOT_STATIC.test(rest)) return null; if (NOT_STATIC.test(rest) || !fitsFile(rest)) return null; const [, view = "", ref, ...file] = rest.split("/"); if (!STATIC_VIEWS.has(view)) return null; if (BROWSED.has(view) && ref && ref !== repo.default_branch) return null; if (view === "commits" && file.length > 0) return null;392 unmodified linesExpand all